![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
awk question
Hello Peeps,
How can I use awk to strip the filename off the end please ? /dir/dir/dir/dir/filename ? Thanks, Dave |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Code:
echo '/dir/dir/dir/dir/filename' | awk -F/ -v OFS=/ '{NF--;$1=$1;print}'
|
|
#3
|
|||
|
|||
|
i would do this instead. translate the / to a space. then awk the 5th field.
tr "/" " " ./file | awk '{print $5}' |
|
#4
|
||||
|
||||
|
Quote:
|
|
#5
|
|||
|
|||
|
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.
|
|
#6
|
||||
|
||||
|
Quote:
but why do you need it here exactly? |
|
#7
|
|||
|
|||
|
cant we use basename
Is basename a HP-UX command only? Can it be used across different flavors?
|
|||
| Google The UNIX and Linux Forums |