The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-09-2006
Registered User
 

Join Date: Mar 2006
Posts: 20
awk question

Hello Peeps,

How can I use awk to strip the filename off the end please ?

/dir/dir/dir/dir/filename ?

Thanks,
Dave
Reply With Quote
Forum Sponsor
  #2  
Old 05-09-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,014
Code:
echo '/dir/dir/dir/dir/filename' | awk -F/ -v OFS=/ '{NF--;$1=$1;print}'
Reply With Quote
  #3  
Old 05-09-2006
Registered User
 

Join Date: Jan 2006
Posts: 31
i would do this instead. translate the / to a space. then awk the 5th field.


tr "/" " " ./file | awk '{print $5}'
Reply With Quote
  #4  
Old 05-09-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,014
Quote:
Originally Posted by wxornot
i would do this instead. translate the / to a space. then awk the 5th field.


tr "/" " " ./file | awk '{print $5}'
why do you need a 'tr'?
Reply With Quote
  #5  
Old 05-09-2006
Registered User
 

Join Date: Jan 2006
Posts: 31
tr means translate. It's a cool function, you can translate most things from one character to another. It works like sed more or less, just one more tool to have in your unix bag of tricks.
Reply With Quote
  #6  
Old 05-09-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,014
Quote:
Originally Posted by wxornot
tr means translate. It's a cool function, you can translate most things from one character to another. It works like sed more or less, just one more tool to have in your unix bag of tricks.
ah, i see - thanks.
but why do you need it here exactly?
Reply With Quote
  #7  
Old 05-09-2006
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 364
cant we use basename

Is basename a HP-UX command only? Can it be used across different flavors?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0