I have a file as below:
10temp3
20/temp4
28 temp 5
I am using the below command for splitting the lines and get the last number in the line.
awk -F"temp" '{print $NF}' temp3
the ouput i got is :
> awk -F"temp" '{print $NF}' temp3
10temp3
20/temp4
28 temp 5
Surprisingly if i use nawk i am getting the expected output.
> nawk -F"temp" '{print $NF}' temp3
3
4
5
>
May i know the reason why?
Is awk not supporting the string mentioned as a separator?
Indeed Solaris
awkonly considers a single character. I’d say it’s probably due to tradition, and exactly the reason whynawkis shipped, as well.The
-Fswitch is really special: it’s taking the first character of your quoted string, and discarding the rest, so thetremains — which stands for “look for tab as field separator”.