4 ms·
The one thing this is missing is a search/replace example. That's a very common thing to do and annoyingly clunky in Awk.
by tieTYT 12y ago
The one thing this is missing is a search/replace example. That's a very common thing to do and annoyingly clunky in Awk.
- shawkinaw 12y agoThat's why awk is so often used with sed, as awk is great for the first part while sed is very good for the second. For example: echo $BUNCH_OF_TEXT | awk '/amazing/ {print $1, $3}' | sed 's/amazing/mildly interesting/'
- sxv 12y ago| awk 'sub(/annoyingly clunky/, "pretty easy")'
- jnazario 12y agoa lot of people pipe to sed but you don't need to. you can do regex subs right in awk. see sub and gsub. sub(r, t, s) substitutes t for the first occurrence of the regular expression r in the string s. If s is not given, $0 is used. gsub same as sub except that all occurrences of the regular expression are replaced; sub and gsub return the number of replacements. (this is awk from osx, which i think is nawk)
- favadi 12y agoIf you have gawk, use gensub instead.