cut filename extension | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

cut filename extension

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-28-2010
Essbaumer Essbaumer is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 28 July 2010, 3:31 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
cut filename extension

I need a small script (sh) to remove in a variable the filename extension.
Example:
f = "testfile.txt"
and I need a $a with "testfile".
Some one a idea?
Sponsored Links
    #2  
Old 07-28-2010
pravin27 pravin27 is offline Forum Advisor  
Advisor
 
Join Date: Sep 2009
Last Activity: 7 August 2014, 10:25 AM EDT
Location: ./India/Banglore
Posts: 1,204
Thanks: 53
Thanked 269 Times in 262 Posts

Code:
f=testfile.txt ; a=`basename $f ".txt"` ;echo $a

The Following User Says Thank You to pravin27 For This Useful Post:
f14f21 (07-28-2010)
Sponsored Links
    #3  
Old 07-28-2010
Essbaumer Essbaumer is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 28 July 2010, 3:31 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks
    #4  
Old 07-28-2010
tukuyomi tukuyomi is offline
Registered User
 
Join Date: Aug 2009
Last Activity: 17 September 2014, 3:37 PM EDT
Location: France
Posts: 318
Thanks: 19
Thanked 81 Times in 76 Posts
Using shell builtins (sh, bash and probably others too)

Code:
#!/bin/sh

a='testfile.test.txt'

echo "Filename: ${a%.*}"
echo "Extension: ${a##*.}"

exit 0


Last edited by tukuyomi; 07-28-2010 at 05:12 PM..
The Following User Says Thank You to tukuyomi For This Useful Post:
f14f21 (07-28-2010)
Sponsored Links
    #5  
Old 07-29-2010
DarkSwiss DarkSwiss is offline
Registered User
 
Join Date: Mar 2010
Last Activity: 3 September 2010, 10:06 AM EDT
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts

Code:
echo $FILENAME |sed 's/\(.*\)..../\1/'

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Filename from splitting files to have the same filename of the original file with counter value natalie23 Shell Programming and Scripting 3 11-13-2009 05:15 AM
script takes the whole filename instead of just extension wolverine999 UNIX for Dummies Questions & Answers 1 05-20-2009 02:49 PM
changing filename extension Hiso Shell Programming and Scripting 3 01-24-2009 08:02 AM
separating filename and extension lucaspewkas Shell Programming and Scripting 2 04-06-2007 07:07 AM
filename extension check - regular expression devs Shell Programming and Scripting 4 03-02-2007 02:01 PM



All times are GMT -4. The time now is 07:40 AM.