[Techtalk] cut command, print just last field
Sabina Serbu
sabina.serbu at unine.ch
Wed Nov 19 10:23:48 UTC 2008
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
--
Sabina Serbu
Institut d'informatique
Université de Neuchâtel
+41 32 718 2724
http://members.unine.ch/sabina.serbu
More information about the Techtalk
mailing list