-   Linux - Newbie (
-   -   Not able to extract last column from awk (

vinaytp 05-20-2011 02:48 AM

Not able to extract last column from awk
Hi All,

I have a basic question of awk.


echo $var | awk '{ FS = ":" ; print $NF }'

I am trying to extract last column from the above awk one liner. I am not getting where am I getting wrong !!


EricTRA 05-20-2011 02:58 AM


If you're trying to get sls as a value, at least that's what I understand from the above, then you need to set your field separator to / instead of : and also if I'm not mistaking take the FS declaration outside the {} like this:

echo $var | awk -F'/' '{ print $5 }'
if you want to get sls as value. If the value of $var is different and you always want the last column, then substitute $5 for $NF as in your first post.

Kind regards,


vinaytp 05-20-2011 03:08 AM

Many Thanks sir,

Actually while posting I made that mistake of putting ":" instead of '/' . I did not have a chance to copy/paste from terminal.

Thanks again !!

EricTRA 05-20-2011 03:09 AM


You're welcome. If you consider your problem solved then please mark the thread as such. Have fun with Linux.

Kind regards,


grail 05-20-2011 05:27 AM

As long as we realise that awk is in no way needed for this task??

echo ${var##*/}

All times are GMT -5. The time now is 07:23 AM.