Search This Blog

2015-01-05

Print n'th column to end of line in awk

If you have output where you only want a certain number of colums printed in awk you can easily modify how awk loops through to display entries.

The easiest method is a simple for loop where i=column

The following grabs me the cmdline entry required for kexec. Or what would be included in /proc/cmdline

awk /kernel.*console/'{for(i=3;i<=NF;++i)printf("%s ",$i)}' /boot/grub/grub.conf


References:
http://www.shellhacks.com/en/Printing-Specific-Columns-Fields-in-Bash-using-AWK
http://stackoverflow.com/questions/17091500/awk-command-to-print-until-end-of-line
http://stackoverflow.com/questions/1602035/print-third-column-to-last-column

No comments:

Post a Comment