Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

cut filename extension

👤 Login to reply

    #1  
Old 07-28-2010
Essbaumer Essbaumer is offline
Registered User
 
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
 
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
 
Thanks
    #4  
Old 07-28-2010
tukuyomi tukuyomi is offline
Registered User
 
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
 
Code:
echo $FILENAME |sed 's/\(.*\)..../\1/'

Sponsored Links
👤 Login to reply

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 01:34 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?