4 ms·
Literally the reason AWK was created
by DominoTree 7y ago
Literally the reason AWK was created
- baldfat 7y agoAWK has been and will forever been under appreciated. It is a fantastic tool. I always preferred it to Perl myself.
- 52-6F-62 7y agoI use it multiple times a week for printing/copying tabular data from space-delimited files. It's not the most arcane usage but it would probably take several lines to do what awk does in one. I don't even know much awk! Learning any bit of awk is worth every moment of the investment. cat somefile.txt | awk '{ print $1 "\t" $2 }' On mac I pipe to `pbcopy`. Saves me several minutes each time.
- keithnoizu 7y agoI don't use it quite that frequently but awk/sed is a strong addition to the toolbox.
- flukus 7y agoBash is actually pretty decent at this by itself if you don't have a lot of extra columns: cat somefile.txt | while IFS=" " read one two; do echo -e "$one\t$two"; done IME the pattern matching is where awk really shines.
- 52-6F-62 7y agoI do have a ton of extra columns I'm filtering out but that's really good. I'll try it on. Thanks!
- rmilk 7y agoAlso see basic Unix utilities like cut / paste (and colrm if your *nix has it, not sure if MacOS does) as these do the same column selection and printing and support simple options for delimiter and field number selection instead of writing a parser. cut -d’ ‘ -f 1,2 < some file.txt
- rmilk 7y agoHaving extensively used AWK and PERL, I don’t agree. AWK works for simple things, but has significant limitations especially for more complex parsing you might do in a dozen lines of PERL. Subroutines don’t return complex structures, Strict mode declaration checking, hashes, foreach style iterators are much less functional or missing in AWK. Multi layer structures are also trivial in PERL (hash table or array composed of child hash or array). Finally, AWK versus GAWK versus NAWK compatibility is an issue.