5 ms·
I really wish awk were less awkward to type (no pun intended). The single quotes plus the brackets is a brutal combo. Does anyone know how to achieve the foll
by johnrob 16y ago
I really wish awk were less awkward to type (no pun intended). The single quotes plus the brackets is a brutal combo.
Does anyone know how to achieve the following command in a more type friendly way?:
awk '{print $1}'
- robertduncan 16y agocut -f1
- johnrob 16y agoNot working for me... > echo '1 2 3 4' | awk '{print $1}' 1 > echo '1 2 3 4' | cut -f1 1 2 3 4
- pmarin 16y agoecho '1 2 3 4' | cut -d' ' -f1 By default cut uses TAB as delimiter
- nimrody 16y agoNot to be picky, but still not good enough: echo '1 2 3 4' | cut -d' ' -f2 'cut' fails when fields are separated by multiple spaces.
- pmarin 16y agoOk. > echo '1 2 3 4' | sed 's/ */\t/g' | cut -f2 2
- molinari 16y agoI usually pipe through a whitespace-to-single-tab command. So echo '1 2 3 4' | sp2tab | cut -f2 would be equivalent to echo '1 2 3 4' | awk '{print $2}' but quicker to write.
- deleted 16y ago[deleted]
- Kototama 16y agoecho "1 2 3 4" | tr -s " " | cut -f1 -d " " tr is nice!
- cma 16y agoDoesn't work, gets caught on leading spaces: echo ' 1 2 3 4' | tr -s " " | cut -f1 -d " " > echo ' 1 2 3 4' | awk '{print $1}' >1
- pmarin 16y agoActually the single quotes are not part of the Awk language. They are used by the posix shell to preservers the literal meaning of the characters, in this case { } and $. they are not needed in self contained Awk scripts.
- Nick_C 16y agoI see there's a bunch of replies, some with more and more commands through a pipe. Seriously, if you are going to be using a shell, you will be typing a ' char all the time, so probably better to just get used to it rather than go through all those convolutions with tr and cut.