Basic Command-Line Data Processing in Linux
symkat.com
symkat.com
my norm is cat file | perl -p -e "s/.from ([0-9\.]+) ./\1/g" to get the ip out of the same datafile.
regex's seem to help with messy data or data that contains inconsistent delimiters.
(some of the stars got stripped by HN so the above won't work)
Try putting a couple of spaces in front of your code line, like this:
cat file | perl -p -e "s/.*from ([0-9\.]+).*/\1/g"
See http://news.ycombinator.com/formatdocEdit: for simple regexes, sed works well, too, and probably loads slightly faster than perl.
http://anyall.org/blog/2009/09/dont-mawk-awk-the-fastest-and...
Also, for programmers, I'd recommend ack over grep.
My MO these days is if it's anything more complicated than an awk one-liner like awk '{print $2 " " $NF}', I'll use Python or, lately, Ruby. (Perl would be fine, too, if I used it in other contexts often enough.)
That said, there's nothing quite like, well, programming your environment. The extent to which you can manipulate files, directories, and text in *nix right out of the box makes me feel privileged to understand it. I can remember a time when renaming a bunch of images en masse seemed tantalizing but out of reach. I've since learned quite a bit, and even though it's relatively mundane now, it still feels magical. Upthread, someone called it "moving mountains." That's precisely it, and I love it.
Yes, yes. I'm a complete and utter nerd, etc.
Which I guess just goes to reinforce the Unix philosophy of tools that do one job and do it well.
http://www.gnu.org/software/coreutils/manual/html_node/Openi...
http://www.gnu.org/software/coreutils/manual/ To read on the command line, try:
info coreutils
Also see,