set -- `awk -F, 'NR==1 { print $NF; next } { last=$NF } END { print last }' QDB_20071126_002.bad`
firstvariable=$1
lastvariable=$2
You could do it with two separate awk invocations or something, but the above is more efficient (although somewhat obscure, the set -- `command` trick is a standard shell programming idiom).
Thanks for your quick reply.
Your command actually prints the last field of first and last line, whereas what i need is the number of fields of first and last line, to be assigned to variables.
Lines are comma-separated.
The below command prints number of fields of each line of the comma-separated file:
cat QDB_20071126_002.bad | awk -F"," '{ print NF }'
6
7
7
7
2
I need to take '6' and '2' and assign it later.
Help me out on this..