I needed to grab all the fields (command line args) from the “history” command output. I started to do what I have always done in the past (assuming you need fields 4 through the end).
history | awk -v col=4 '{ for (x=col; x<=NF; x++) {
printf $x " "; }; print " " }'
But I found an easier way:
history | awk '{$1=$2=$3="";print $0}'
or
history | awk '{$1=$2=$3=""}1'
Here is a practical use of this:
history | awk '{$1=$2=$3="";print $0}' | sort | uniq -c | sort -n # frequency of command use
I constantly use awk, grep, and sed to work out issues. My philosophy in using awk, grep, and sed vs Perl is two fold. These fundamental tools are universally found on *nix servers - even ones that have severe security requirements (think STIG here). The second reason is grounds for a flame war. I believe scripts using these tools are easier to maintain by a team than Perl. Perl has so many ways of accomplishing a task that the code becomes very personalized and styled to the coder's preferences. It be comes a "child" that only the father can take care of. But I digress...
Enjoy!