👤
Home Man
Search
Today's Posts
Register

The Solaris Operating System, usually known simply as Solaris, is a Unix-based operating system introduced by Sun Microsystems. The Solaris OS is now owned by Oracle.

Get file name in shell scrip loop: bad substitution

Tags
looping, shell script, substring

👤 Login to reply

 
Thread Tools Search this Thread
# 1  
Old 05-02-2011
Get file name in shell scrip loop: bad substitution

Hi guys. Good day, morning, afternoon or night, depending on where you live.
I have a script shell in which I am looping on files (absolute path) see code section above.
I always have an error: bad substitution.

Is it because my variable file is the index of the loop and not a normal string?
Code:
for file in $home/$input/*.txt
do
    echo ${file##*/}.log
done

I specify that I need to loop on the absolute path, as I do not want to go inside the files folder, as I am running the script from a bin folder and want to stay in there.

Thanks for your help.
# 2  
Old 05-02-2011
Is that you looking for ?

Code:
for file in $home/$input/*.txt do     basename $file | sed 's/txt/log/'  done

# 3  
Old 05-02-2011
Hi itkamaraj.
Thanks, it's working well.
I have actually customized it into:

Code:
for file in $home/$input/*.txt do     basename $file | sed 's/.txt//'  done

Actually, I will reuse this base name for generating other logs file containing different extensions (bad.log, discard.log...)

Issue is solved.
Thanks.
# 4  
Old 05-02-2011
Code:
for file in $home/$input/*.txt
do 
  echo ${file%%.*}.log
done

# 5  
Old 05-02-2011
Hi rdcwayx.
Thanks for you answer, my problem was solved.

However, your command does not work as it is still returning the entire path I wanted to get rid:
Code:
/........./filename.log

So first solution suggested was better.
Thanks.
👤 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
Help with Shell Scrip in Masking particular columns in .csv file or .txt file using shell script Mahesh G Shell Programming and Scripting 5 11-06-2016 11:59 PM
Bad substitution issues.. but why? kidi UNIX for Beginners Questions & Answers 13 08-25-2016 05:48 PM
Bad substitution kenshinhimura Shell Programming and Scripting 7 10-16-2014 04:44 PM
Bad substitution error in shell script man4ish Shell Programming and Scripting 5 11-22-2012 10:59 PM
Why I get bad bad substitution when using eval? 915086731 Shell Programming and Scripting 5 08-19-2011 07:38 AM
Make: Bad Substitution nadne Programming 3 05-19-2011 08:50 AM
bad substitution Muhammad Rahiz UNIX for Dummies Questions & Answers 2 01-11-2011 05:05 AM
how to combine two files into one file using shell scrip netbanker Shell Programming and Scripting 2 12-06-2010 05:34 PM
Bad substitution errors in shell script Jackinthemox Shell Programming and Scripting 2 03-19-2010 05:25 AM
Bad Substitution D_Redd74 Shell Programming and Scripting 3 02-07-2007 04:48 PM


All times are GMT -4. The time now is 02:28 AM.

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