News for hackers. Stuff that matters.
Re:Basic Command-Line Data Processing in Linux by pbrumm on Sunday August 29, 2010 @10:00PM (#1645156)
Even after using linux command line for years it is always useful to see how others use it. I tend to overuse perl regex's to massage the data how I want it and underuse awk.

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)

Re:Basic Command-Line Data Processing in Linux by nitrogen on Monday August 30, 2010 @03:43AM (#1645644)
(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/formatdoc

Edit: for simple regexes, sed works well, too, and probably loads slightly faster than perl.

Re:Basic Command-Line Data Processing in Linux by jimbokun on Sunday August 29, 2010 @11:01PM (#1645254)
Also, tools like Awk and friends can be ridiculously fast and concise.

http://anyall.org/blog/2009/09/dont-mawk-awk-the-fastest-and...