👤
Home Man
Search
Today's Posts
Register

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

 
Thread Tools Search this Thread
# 1  
Old 07-28-2010
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?
# 2  
Old 07-28-2010
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)
# 3  
Old 07-28-2010
Thanks
# 4  
Old 07-28-2010
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)
# 5  
Old 07-29-2010
Code:
echo $FILENAME |sed 's/\(.*\)..../\1/'

👤 Login to reply

« Previous Thread | Next 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
[BASH] Getting a filename its extension sea Shell Programming and Scripting 7 05-07-2015 04:58 AM
Get latest filename without extension sumang24 Shell Programming and Scripting 7 12-11-2012 02:38 PM
Rename all files (filename with spaces) to different extension mac4rfree Shell Programming and Scripting 1 06-13-2012 03:05 AM
Script to add extension to filename repiv Shell Programming and Scripting 2 07-22-2011 05:30 PM
removing the filename extension daflore Shell Programming and Scripting 5 03-03-2011 04:43 PM
Getting filename with entire path without extension amicableperson Shell Programming and Scripting 3 01-16-2011 08:13 PM
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 08:36 AM.

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