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}'
Does anyone know how to achieve the following command in a more type friendly way?:
awk '{print $1}'
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.
> echo '1 2 3 4' | awk '{print $1}'
1
> echo '1 2 3 4' | cut -f1
1 2 3 4
echo '1 2 3 4' | cut -d' ' -f1
By default cut uses TAB as delimiter echo '1 2 3 4' | cut -d' ' -f2
'cut' fails when fields are separated by multiple spaces. > echo '1 2 3 4' | sed 's/ */\t/g' | cut -f2
2 echo '1 2 3 4' | sp2tab | cut -f2
would be equivalent to echo '1 2 3 4' | awk '{print $2}'
but quicker to write.tr is nice!
echo ' 1 2 3 4' | tr -s " " | cut -f1 -d " "
>
echo ' 1 2 3 4' | awk '{print $1}'
>1