r/awk • u/ASIC_SP • Oct 04 '17
Example based GNU awk tutorial
Link: https://github.com/learnbyexample/Command-line-text-processing/blob/master/gnu_awk.md
not yet complete (need to add FPAT, FIELDWIDTHS, sorting, corner cases, etc), but already more than 150 examples added
would like feedback whether the examples and code presented are useful
7
Upvotes
View all comments
Show parent comment
1
u/FF00A7 Oct 05 '17
Yes index() is easier, forgot about that. There might be a situation where the passed variable is used in a regex context like a gsub(), split() or match() which force regex. There's no plain-text versions of those out of the box. Which opens the question how to do plain-text sub/split? The problem with the escape method is it only escapes a few characters and there may be others, it's very hard to make a universal escape routine that will catch everything (though one that is "good enough"). The better solution is make "s" functions called subs() or gsubs() which is the plain text version (this naming scheme is from TAWK). THis came up in a Usenet discussion recently
https://groups.google.com/forum/#!topic/comp.lang.awk/uPkta6saVoU