|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | 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 do I get only the file name from a listing?
Hi,
I am trying to get a file name only. Could anyone help me on the same. Meaning I have a file say list.out which holds below output ./xyz/abc.txt ./xyz/hij.txt I want an output as below abc.txt hij.txt i.e I want to delete everything before abc.txt Please help me out if any one has the ans. |
| Sponsored Links | ||
|
|
|
#2
|
|||
|
|||
|
Please use a more useful title next time. This cannot possibly be that urgent - i.e., your system will not crash if you don't know how to do this. The command you want is basename Code:
>echo basename /path/to/file/file.txt file.txt > |
|
#3
|
||||
|
||||
|
Code:
xargs -n1 < list.out basename abc.txt hij.txt |
|
#4
|
|||
|
|||
|
cat list.out | awk -F "/" '{print $3}'
|
|
#5
|
||||
|
||||
|
Awk is incredibly much faster (more noticeable for larger list.out files) - and handles filenames with spaces, but I'd change it slightly Code:
awk -F/ '{print $NF}' list.out0.05 seconds for 8000+ files, versus 6.3 seconds using xargs. (not that I'm a fan of the UUOC club - it took the same time with or without cat!) It's even quicker than sed (0.09 seconds) Code:
sed "s+.*/++" list.out Last edited by scottn; 12-05-2009 at 12:08 PM.. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Rename multiple file from file listing | yshahiac | Shell Programming and Scripting | 5 | 02-09-2009 03:42 PM |
| file listing ... | thepurple | Solaris | 3 | 12-28-2007 08:39 AM |
| listing file with other format | happyv | Shell Programming and Scripting | 3 | 06-26-2007 06:17 AM |
| Recursive directory listing without listing files | psingh | UNIX for Dummies Questions & Answers | 4 | 05-10-2002 10:52 AM |
| File listing | Astudent | UNIX for Dummies Questions & Answers | 5 | 10-25-2000 05:36 PM |