To use AWK to disable the first and last fields:
awk '{$1 = ""; $NF = ""; print}' inputfile
Unfortunately, this leaves field separators, so
aaa bbb ccc
becomes
[space]bbb[space]
To do this, use the kurumi answer, which will not leave extra spaces, but in a way that meets your requirements:
awk '{delim = ""; for (i=2;i<=NF-1;i++) {printf delim "%s", $i; delim = OFS}; printf "\n"}' inputfile
This also fixes a couple of issues in this answer.
To summarize this:
awk -v skipstart=1 -v skipend=1 '{delim = ""; for (i=skipstart+1;i<=NF-skipend;i++) {printf delim "%s", $i; delim = OFS}; printf "\n"}' inputfile
You can then change the number of fields to skip at the beginning or end by changing the variable assignments at the beginning of the command.
Dennis Williamson Feb 10 '11 at 15:54 2011-02-10 15:54
source share