Thursday, October 04, 2012

Awk display / print file from column N onwards


This can be piped to any output to display the lines from the second column onwards.
awk -F: -v nr=N '{ for (x=nr; x<=NF; x++) {printf $x " "};print " ";}'
An example usage, find the first disk re-inited by MapRFS this month.
find . -name mfs.log -exec grep -H ^2012\-10\-* {} \; | grep spinit.cc:1002 | awk -F: -v nr=2 '{ for (x=nr; x<=NF; x++) \
{printf $x " "};print " ";}' | awk -v nr=2 '{ for (x=nr; x<=NF; x++) {printf $x " "};print " ";}' | sort -n | head -n 5

UPDATE:

Just realized cut could do this in a much simpler wa
cut -d : -f N-

where N is the column from where you need to display the lines.