ejdv
1
Hi,
Don't know if this is Solaris 10 or that the shell on Solaris 10 is working against me.
But this works fine on HP-UX 11i, but not on Solaris 10:
# cat /tmp/test_file
1:een
2:twee
3:drie
# cat /tmp/test_file | /bin/nawk 'END {print $NF}'
# cat /tmp/test_file | /bin/nawk '{} END {split($1,result,":");print result[1]}'
#
Also tried to use awk iso nawk.
And tried sh, ksh and bash.
Any ideas why this is not working ?
---------- Post updated at 11:04 AM ---------- Previous update was at 11:03 AM ----------
Here the HP-UX 11i output:
# cat /tmp/test_file | /bin/nawk 'END {print $NF}'
3:drie
# cat /tmp/test_file | /bin/nawk '{} END {split($1,result,":");print result[1]}'
3
Not every awk keeps the value of $0,$1..$NF after the END clause... (This behaviour is unspecified by the standard) Try:
nawk '{last=$NF} END{print last}' infile
Try:
/usr/xpg4/bin/awk '{.....}' file
ejdv
4
nawk '{last=$NF} END{print last}' infile
That is indeed working.
What about the other example ?
# cat /tmp/test_file | /bin/nawk '{} END {split($1,result,":");print result[1]}'
---------- Post updated at 11:17 AM ---------- Previous update was at 11:15 AM ----------
/usr/xpg4/bin/awk '{.....}' file
Is not working.
Same result.
Try:
nawk -F: '{last=$1} END{print last}' infile
1 Like
ejdv
6
Perfect !
Thanks.
---------- Post updated at 01:18 PM ---------- Previous update was at 11:54 AM ----------
The 'trick' is to save the fields one wants use in the end clause in the beginning.
Example:
nawk '{f1=$1; f2=$2; f3=$3} END{print f1, f2, f3}' infile