On shell, I pipe to awk when I need a particular column.
This prints column 9, for example:
... | awk '{print $9}'
How can I tell awk to print all the columns including and after column 9, not just column 9?
If you notice awk 'print $1' prints first word of each line. If you use $3, it will print 3rd word of each line.
awk '{ print $2; }' prints the second field of each line. This field happens to be the process ID from the ps aux output. xargs kill -${2:-'TERM'} takes the process IDs from the selected sidekiq processes and feeds them as arguments to a kill command.
awk '{ s = ""; for (i = 9; i <= NF; i++) s = s $i " "; print s }'
When you want to do a range of fields, awk
doesn't really have a straight forward way to do this. I would recommend cut
instead:
cut -d' ' -f 9- ./infile
Added space field delimiter due to default being a tab. Thanks to Glenn for pointing this out
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With