Strip extention from filename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Strip extention from filename
# 1  
Old 04-03-2006
Strip extention from filename

Hey,

How to strip the extention from filename?

MY_XML.xml -> MY_XML
MY_TEST_FILE.txt -> MY_TEST_FILE
HELLO_WORLD.xls -> HELLO_WORLD

Thanks in advance!
# 2  
Old 04-03-2006
Say filename holds each of those names. Then this would work

Code:
${filename%\.*}

gives the filename sans the extension. If the file contains more than one . , i.e. like filename.1.2.3, then the above would give filename.1.2

If you need to remove all sub.extensions, then it would be
Code:
${filename%%\.*}

# 3  
Old 04-03-2006
echo $filename|cut -d"." -f1
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed to remove all lines in file that are not .vcf.gz extention

I am trying to use sed to remove all lines in a file that are nor vcf.gz. The sed below runs but returns all the files with vcf.gz in them, rather then just the ones that end in only that extention. Thank you :). file ... (9 Replies)
Discussion started by: cmccabe
9 Replies

2. Shell Programming and Scripting

add a extention to all files

I'm working on implementing a mail indexer and it currently saves every file with a series of numbers with no extension. ex. 021545545544 I was wondering if someone could point me in the correct direction for a script that would check all the files and give it a .eml extension if it doesn't... (1 Reply)
Discussion started by: binary-ninja
1 Replies

3. UNIX for Dummies Questions & Answers

problem with packages that have .tar.gz in the extention

Hi Everybody , I want to install some packages on sun Solaris , I download the packages it was for example openssl.tar.gz it is not data stream or sun packages , so I search and I found command called make solve this problem , but the packages of this command not found on my machine, so I... (7 Replies)
Discussion started by: hard_revenge
7 Replies

4. Shell Programming and Scripting

How to strip off the leading filename from 'wc -l' command

Hi... can anyone please tell how do i strip off the leading filename from the wc -l command.... when i fire command wc -l new1 ... its giving output as 14 new1 i want the output as just '14'... i need to use this value in the calculations in the later part of the script..... (2 Replies)
Discussion started by: swap21783
2 Replies

5. Shell Programming and Scripting

Listing files in a given directory with given extention

for some reason my code does not give the right number of files. can omeone help me please? (2 Replies)
Discussion started by: andrew1400
2 Replies

6. Shell Programming and Scripting

Filename from splitting files to have the same filename of the original file with counter value

Hi all, I have a list of xml file. I need to split the files to a different files when see the <ko> tag. The list of filename are B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml ... (3 Replies)
Discussion started by: natalie23
3 Replies

7. Shell Programming and Scripting

Add extention to files recursively.

I want to add a .txt extension to all files in a directory and it's sub directories. So far I have managed to come up with this for the current directory but how do I do this recursively? for e in *; do mv "$e" "`echo $e | sed -e 's/\ /_/g'`.txt"; done Thanks (5 Replies)
Discussion started by: lewk
5 Replies

8. UNIX for Dummies Questions & Answers

Strip part from filename

I've many file like this 01-file 01_-_file 01_-_file 01_-_file 01_-_file 01-file I would remove bold part from filename. Suggestions?Thanks (4 Replies)
Discussion started by: cv313x
4 Replies

9. Shell Programming and Scripting

gzcat into awk and then change FILENAME and process new FILENAME

I am trying to write a script that prompts users for date and time, then process the gzip file into awk. During the ksh part of the script another file is created and needs to be processed with a different set of pattern matches then I need to combine the two in the end. I'm stuck at the part... (6 Replies)
Discussion started by: timj123
6 Replies
Login or Register to Ask a Question