[Techtalk] cut command, print just last field

R. Daneel Olivaw linuxchix at r-daneel.com
Wed Nov 19 20:51:01 UTC 2008


Hi there,

Usually, I use 'basename' and it's opposite 'dirname' quite often ...

This however works only with pathnames, as you gave an example with '/'
as a separator.

Afaik, 'cut' is unable to do what you're looking for.

bye,

R. Daneel Olivaw,
The Human Robot Inside.


Le mercredi 19 novembre 2008 à 11:23 +0100, Sabina Serbu a écrit :
> Hi,
> 
> I'm trying to get the local directory (without the absolute path) on my
> shell.
> 
> For the moment, I am using awk:
> 
>   pwd | awk -F'/' '{print $NF}'
> 
> Which works just fine. However, I was just wondering, do you know any
> way to do this using the 'cut' command? 
> 
> I could not use something like
>   pwd | cut -d'/' -f5
> because this would display the last field only if there are 5 fields.
> Unless there was a way for 'cut' to know the number of fields, as NF in
> awk..?
> 
> Thanks!
> Sabina
> 
> 
> 
> 
> 
> 
> 



More information about the Techtalk mailing list