Unix/Linux Go Back    


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.

separating filename and extension

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-06-2007
lucaspewkas lucaspewkas is offline
Registered User
 
Join Date: Apr 2007
Last Activity: 6 April 2007, 2:27 AM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
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:


Code:
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)

Thanks!
Sponsored Links
    #2  
Old Unix and Linux 04-06-2007
Raghuram.P Raghuram.P is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 4 September 2007, 2:03 AM EDT
Posts: 44
Thanks: 0
Thanked 1 Time in 1 Post
HI,
You can get the filename alone excluding the directory using following command
for file in `ls test_suite/*.args`
do
F_NAME=$(basename ${file})
done

Thanks
Raghu
The Following User Says Thank You to Raghuram.P For This Useful Post:
mohit_iitk (02-13-2012)
Sponsored Links
    #3  
Old Unix and Linux 04-06-2007
radoulov's Unix or Linux Image
radoulov radoulov is offline Forum Advisor  
Forum Adviser
 
Join Date: Jan 2007
Last Activity: 9 January 2017, 4:40 AM EST
Location: Варна, България / Milano, Italia
Posts: 5,690
Thanks: 184
Thanked 629 Times in 586 Posts

Code:
for f in test_suite/*.args;do 
	fn="${f%.*}" 
	printf "filename without path and extension: %s, extension only: %s\n" "${fn##*/}" "${f##*.}"  
done

With bash you can do something like this (if I understand correctly the requirement):

Code:
set test_suite/*.args
set "${@##*/}"
printf "%s\n" "${@%.*}">file.out


Last edited by radoulov; 04-06-2007 at 07:40 AM..
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
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
cut filename extension Essbaumer Shell Programming and Scripting 4 07-29-2010 05:18 AM
changing filename extension Hiso Shell Programming and Scripting 3 01-24-2009 08:02 AM



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