4 ms·
AWK has been and will forever been under appreciated. It is a fantastic tool. I always preferred it to Perl myself.
by baldfat 7y ago
AWK 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