Awk + Print All Line Content Except $1
Answer :
If you set $1
to ""
you will leave the delimiting space. If you don't want to do that you have to iterate over the fields:
awk '{for (f=2; f<=NF; ++f) { if (f!=2) {printf("%s",OFS);} printf("%s",$f)}; printf "\n" }'
Edit: fixed per Gilles' comment.
Another way to do the same thing:
awk '{d = ""; for (f=2; f<=NF; ++f) {printf("%s%s", d, $f); d = OFS}; printf("\n") }'
Somehow I think this would be so much easier and more intuitive to do with the cut command:
echo /var/sysconfig/network/my_functions alpha beta gama | cut -d' ' -f 2-
The only problem is that cut doesn't support multiple different types of whitespace at once for delimiters. So if you have spaces or tabs, it won't work.
Comments
Post a Comment