|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | 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 and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
how to cut all string after the last delimiter?
hi all, suppose a string: Code:
abc/def/ghi/jkl/mn.txt and i want to get the file name without the path. however, different files have different paths, therefore the number of delimiter is uncertain. thanks so much! |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
What about something like?
Code:
$ echo "abc/def/gh/joe.txt" | awk -F"/" '{print $NF}'
joe.txt |
| The Following 2 Users Say Thank You to joeyg For This Useful Post: | ||
lan123 (03-06-2012), sunnydanniel (02-28-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Try using basename <full_path_to_file>
$ basename /sndc002/app/appsndc/sndcappl/admin/sndc01.txt sndc01.txt |
| The Following User Says Thank You to bab@faa For This Useful Post: | ||
sunnydanniel (03-01-2012) | ||
|
#4
|
|||
|
|||
|
If you are doing this within a loop, you may want to consider using the built-in feature of bash/ksh parameter expansion. This will save you 1 exec for every loop Code:
v="abc/def/ghi/jkl/mn.txt"
echo ${v##*/} |
| The Following User Says Thank You to chihung For This Useful Post: | ||
sunnydanniel (03-01-2012) | ||
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to split a string with no delimiter | saint34 | Shell Programming and Scripting | 8 | 03-01-2011 02:27 PM |
| Delimiter count in a string. | priyam | Shell Programming and Scripting | 8 | 10-20-2008 11:16 AM |
| Extraction of string from Stringlist using delimiter | spkandy | Shell Programming and Scripting | 3 | 10-03-2008 09:38 AM |
| Parsing string using specific delimiter | primp | Shell Programming and Scripting | 8 | 09-22-2008 01:46 AM |
| creating a delimiter string | satish@123 | Shell Programming and Scripting | 0 | 05-21-2008 05:38 AM |
|
|