![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | 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. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Stripping out extensions when file has multiple dots in name | Nemelis | Shell Programming and Scripting | 8 | 05-14-2008 05:12 AM |
| How to get file extension | shirleyeow | Shell Programming and Scripting | 17 | 01-17-2008 04:40 AM |
| Stripping out the extension of a file name | ramky79 | Shell Programming and Scripting | 4 | 12-28-2006 06:15 PM |
| Stripping out the extension of a file name | ramky79 | Shell Programming and Scripting | 2 | 12-27-2006 10:25 AM |
| stripping last lien off a file | vivekshankar | UNIX for Dummies Questions & Answers | 3 | 05-31-2005 03:35 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Stripping out extension in file name
This command gives me just the filename without any extension:
evrvar =`echo filename.tar | sed 's/\.[^.]*$//'` I am trying to make a change to this command... to make it work for... filename.tar.gz to get just the filename.... currently the command gives me filename.tar by removing only gz... I am new to regular expression... pls help. Thx. |
| Forum Sponsor | ||
|
|
|
|||
|
try this:
Code:
echo filename.tar.gz |awk -F. '{ print $1 }'
Code:
echo filename.tar.gz |cut -d'.' -f1 Code:
echo "filename.tar.gz" | sed 's/\(.*\)\.\(.*\)\.\(.*\)/\1/g' Code:
echo "filename.tar.gz" | sed 's/.......$//g' Last edited by ahmedwaseem2000; 02-25-2007 at 01:08 AM. |
|
|||
|
Thanks for the replies.
can this regular expression be made possible to use for both filename.gz & filename.tar.gz I want to get filename for both of these commands as just filename only: echo "filename.tar.gz" | sed 's/\(.*\)\.\(.*\)\.\(.*\)/\1/g' echo "filename.gz" | sed 's/\(.*\)\.\(.*\)\.\(.*\)/\1/g' thanx in advance. |
|
|||
|
You could use either the awk or the cut solutions they will work in all the scenarios. Here is the sed solution to generalize on both the occasions.
Code:
echo "filename.tar" | sed "s/\([^.*]\)\.\(.*\)*$/\1/g" Last edited by ahmedwaseem2000; 02-25-2007 at 08:09 AM. |
|
|||
|
Quote:
|