Bash script: how do I select second-to-last argument in a list
I am trying to write a bash script that pulls out the second-to-last argument in a list of fields in a text file. The number of fields is variable for each line - eg.
arg1 arg2 arg3 arg4 arg5
arg1 arg2 arg3 arg4 arg5 arg6
arg1 arg2 arg3 arg4
In this case I'd like the script to pull out:
arg4
arg5
arg3
I can use awk to print out the first n arguments ie (cat filename | awk '{print @2}'), but is there an easy way to pull out a certain number of arguments from the end?
|