$0 !~ /something/ is also shorter and very valid. But yours should be fine by POSIX, too:
When an ERE token appears as an expression in any context other than as the right-hand of the ‘˜’ or “!˜” operator or as one of the built-in function arguments described below, the value of the resulting expression shall be the equivalent of: $0 ˜ /ere/
Going by that, !/ere/ is !($0 ~ /ere/) as expected.
Depends on the context. For a script processing large quantities of data, 2x could be a pretty big win. (Though in the specific case of GNU tools, awk actually uses the same DFA matcher that grep does, so it’s probably a wash in any case.)
I finally decided to replace all my use of sed with perl -pe last week. I’m intimately familiar with perl regex syntax, but find posix-style regexes to be mostly confusing and ugly.
Which ones, BREs or EREs? BREs are confusing, horrible, ugly and lack all kinds of useful features and ideally would never have made it into POSIX. EREs are much nicer (though still vastly less feature filled than PCREs).
For
grep -vthere’s a much easier way to invert than the suggestedYou can also use
Am I wrong because that’s not in posix or something?
$0 !~ /something/is also shorter and very valid. But yours should be fine by POSIX, too:Going by that,
!/ere/is!($0 ~ /ere/)as expected.Wrong. POSIX extended regexes aren’t PCRE.
Although GNU grep does have -P too, for perl compatible regex. Doesn’t help awk though.
I guess most grep will be quicker than awk, however.
Unless we are talking an order of magnitude slower, YAGNI.
( repeat 100 cat /usr/share/dict/words ) | time grep '/[aoeiu]..[aeoiu]/' >/dev/nullp9p grep: 0.55s
GNU grep 3.1: 1.3s
busybox grep: 5.2s
ripgrep: 11s
mawk: 2.5s
gawk: 3.7s
nawk: 6.6s
p9p awk: 10s
busybox awk: 11s
GNU sed -n: 4.5s
p9p sed -n: 18s
busybox sed -n: 6.6s
perl: 10s
ruby: 14s
How in the world did you get those timings? I can’t reproduce anything close to them with either GNU grep or ripgrep.
Depends on the context. For a script processing large quantities of data, 2x could be a pretty big win. (Though in the specific case of GNU tools, awk actually uses the same DFA matcher that grep does, so it’s probably a wash in any case.)
Agree on context. For everyday use it seems unlikely to matter, too much.
On that basis, ag is much faster than grep.
While I agree, having to quote and enclose in
/even the most basic search gets tiresome quickly.Quick, somebody write an article on how
sedis better thangrep!GNU sed is very, very slow in comparison to Perl. Several orders of magnitude.
Quick, somebody write an article on how Perl is better than grep!
I finally decided to replace all my use of sed with
perl -pelast week. I’m intimately familiar with perl regex syntax, but find posix-style regexes to be mostly confusing and ugly.Which ones, BREs or EREs? BREs are confusing, horrible, ugly and lack all kinds of useful features and ideally would never have made it into POSIX. EREs are much nicer (though still vastly less feature filled than PCREs).
sedsucks, long livesed -r.Awk is that one tool I feel like I never learned fully enough to appreciate. Thanks for sharing this!
And how do you match literal string contained in a variable ?
With sed and awk you would have to first escape the the special chars (with sed or awk).