AWK is the general-purpose programmatic filter and reporting tool in the Unix pipeline. Sed, grep and cut are specializations for specific use cases whose implementations might have better performance. Perl and Python are probably too general-purpose for writing compact one-liners in a pipeline.
Even though it's more characters, I usually use perl -pe 's/search/replace/' instead of sed in pipelines because it understands /n (and other escape characters I don't remember). Because all it takes is to get burned a couple times for it to be worth sticking with what you know will work.
Skip grep, use awk
61–70 of 136 posts
Re: Skip grep, use awk
#62The author mentions that using awk instead of grep -v is not a good idea, what about: awk '! /something/' Doesn't it reproduce the same behaviour as the following? grep -v 'something'
Re: Skip grep, use awk
#63grep has tons of great option like
-F = fgrep; no regex - way faster
-v = as mentioned in the article
-o = print only matched input, not the entire line
-C = context, print lines before and after the match; can also be used partially with -A (after) and -B (before)
Re: Skip grep, use awk
#64My favourite bad example of using grep was from a big enterprise software vendor to kill one of their processes. It looked something like ps -ef| grep SomeDaemon | grep -v grep | grep -v perl | perl -e ' '
Serious question: what would be a better way to do this?
do_something_with_pids $(ps -C SomeDaemon ho pid)
Though it's GNU procps.Re: Skip grep, use awk
#65is there any awk equivalent for grep "matcha\|matchb" ?
Re: Skip grep, use awk
#66AWK is the general-purpose programmatic filter and reporting tool in the Unix pipeline. Sed, grep and cut are specializations for specific use cases whose implementations might have better performance. Perl and Python are probably too general-purpose for writing compact one-liners in a pipeline.
Even though it's more characters, I usually use perl -pe 's/search/replace/' instead of sed in pipelines because it understands /n (and other escape characters I don't remember). Because all it takes is to get burned a couple times for it to be worth sticking with what you know will work.
Re: Skip grep, use awk
#67Re: Skip grep, use awk
#68Earlier quoted context omitted.
Even though it's more characters, I usually use perl -pe 's/search/replace/' instead of sed in pipelines because it understands /n (and other escape characters I don't remember). Because all it takes is to get burned a couple times for it to be worth sticking with what you know will work.
The Perl version is considerably faster on large files as well. Or at least, it is when compared to the version of BSD sed shipped with OSX.
Re: Skip grep, use awk
#69Earlier quoted context omitted.
Even though it's more characters, I usually use perl -pe 's/search/replace/' instead of sed in pipelines because it understands /n (and other escape characters I don't remember). Because all it takes is to get burned a couple times for it to be worth sticking with what you know will work.
"/n"? What's that? My `man perlre' doesn't say anything about this regexp flag.
Re: Skip grep, use awk
#70No, Perl regular expression are different than extended regular expressions that awk and "grep -E" use.