Today's Posts

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.

separating filename and extension

shell scripts

Login to Reply

Thread Tools Search this Thread
# 1  
Old 04-06-2007
separating filename and extension

Hi (warning: newbie question),
I am writing a script to run a series of tests on a program, which involves a line:

for file in `ls test_suite/*.args`

but later I want to send the output to file.out. But I need to separate the filename and extension somehow...Also $file contains "test_suite/" before each entry as well, how do I get rid of that (I assume it's in a similar way as the separation above)

# 2  
Old 04-06-2007
You can get the filename alone excluding the directory using following command
for file in `ls test_suite/*.args`
F_NAME=$(basename ${file})

The Following User Says Thank You to Raghuram.P For This Useful Post:
mohit_iitk (02-13-2012)
# 3  
Old 04-06-2007
for f in test_suite/*.args;do 
	printf "filename without path and extension: %s, extension only: %s\n" "${fn##*/}" "${f##*.}"  

With bash you can do something like this (if I understand correctly the requirement):
set test_suite/*.args
set "${@##*/}"
printf "%s\n" "${@%.*}">file.out

Last edited by radoulov; 04-06-2007 at 08:40 AM..
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 05:58 AM
Display the .csv extension files based on .done extension fine girija.g6 UNIX for Dummies Questions & Answers 2 03-22-2015 04:41 PM
Remove the last 15 characters of a filename with respect to leave file extension ateya Shell Programming and Scripting 13 02-23-2014 11:46 PM
[Solved] Replace extension of filename stored in a variable rberkers Shell Programming and Scripting 2 02-07-2014 06:02 AM
Get latest filename without extension sumang24 Shell Programming and Scripting 7 12-11-2012 03:38 PM
BASH - Removing the very last character(s) extension of a filename jcdole UNIX for Dummies Questions & Answers 2 07-03-2012 02:43 PM
Rename all files (filename with spaces) to different extension mac4rfree Shell Programming and Scripting 1 06-13-2012 04:05 AM
Script to add extension to filename repiv Shell Programming and Scripting 2 07-22-2011 06:30 PM
removing the filename extension daflore Shell Programming and Scripting 5 03-03-2011 05:43 PM
Getting filename with entire path without extension amicableperson Shell Programming and Scripting 3 01-16-2011 09:13 PM
cut filename extension Essbaumer Shell Programming and Scripting 4 07-29-2010 06:18 AM
script takes the whole filename instead of just extension wolverine999 UNIX for Dummies Questions & Answers 1 05-20-2009 03:49 PM
changing filename extension Hiso Shell Programming and Scripting 3 01-24-2009 09:02 AM
filename extension check - regular expression devs Shell Programming and Scripting 4 03-02-2007 03:01 PM
separating commands mile1982 Programming 2 09-13-2004 12:41 PM

All times are GMT -4. The time now is 09:52 PM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
Show Password