There has been another thread as lorcan said and this seems to be only a continuation of the above thread in a new post.
Please continue to post your question in the same thread so that it would be easier to follow up rather than starting a new thread for the same question.
Assuming I have understood your requirement try this,
Code:
awk ' { if ( NR == 1 ) { head=$0 } else { last = $0 } arr[i++]=$0; }END{ printf "Header is : %s Trailer is : %s\n", head, last; for( x=0; x<i-1; x++) { print arr[x] } }' filename
Code:
Header is : header Trailer is : trailer
header
record 1
record 2
record 3
combined header and trailer is available followed by that
header is available
all the records are displayed
trailer record is not displayed
If this is not what you had asked for, let us know
