![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| extracting date from a filename | laiko | UNIX for Dummies Questions & Answers | 5 | 05-09-2008 02:15 AM |
| mv Filename variable to another filename | gzs553 | Shell Programming and Scripting | 3 | 04-14-2008 01:19 PM |
| shortcut for tar cvf - [filename] | gzip > [filename].tar.gz | bcamp1973 | UNIX for Dummies Questions & Answers | 4 | 12-11-2007 01:45 PM |
| Extracting Filename from Fullpath | njoshi | UNIX for Dummies Questions & Answers | 3 | 04-19-2007 02:34 PM |
| extracting from tar.bz2 | Raom | UNIX for Advanced & Expert Users | 1 | 03-07-2006 06:33 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
extracting only the filename without its extenstion
Hi,
I have a requirement that i need to store only the filename without its extension. Can anyone please help me to do this. For Example, i have stored the filename in a varialble called fname. I need to extract all the charecters before the first occurence of the dot. If fname has value as PG_0008_20050519.xml.gz then i need to extract only "PG_0008_20050519". Please help me to do this. TIA. |
| Forum Sponsor | ||
|
|
|
|||
|
If the extension is always the same:
Code:
fname=`basename $fname xml.gz` Code:
fname=`echo $fname | cut -d\. -f1`
fname=${fname}.
__________________
[url=http://chuckb.1le.net/]My website[/url] |
|
|||
|
some more ways
the first is one with awk echo `basename <program-path>` | awk -F"." '{print $1}' this one is with sed but no of characters in extension need to be known in prior for 3 character extension echo `basename <program-path>` | sed -e 's/\....//' advancement to the above method, no of characters in extension need not be known echo `basename <program-path>` | sed -e 's/\..*//' |
|||
| Google UNIX.COM |