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, solaris, 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-03-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 syntax errors Demas Homework & Coursework Questions 9 01-24-2017 04:39 PM
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-07-2016 12:59 AM
reading the values from a file in C Shell for loop raghu.iv85 Shell Programming and Scripting 2 04-09-2012 01:49 AM
for loop substitution error Daniel Gate Shell Programming and Scripting 5 09-20-2011 01:57 PM
how to combine two files into one file using shell scrip netbanker Shell Programming and Scripting 2 12-06-2010 06:34 PM
How to convert shell scrip to binaric command raghunsi UNIX for Advanced & Expert Users 1 02-03-2010 02:27 AM
Shell variables substitution in a file axes Solaris 2 11-09-2009 01:26 AM
Using cp command inside shell scrip yoavbe Shell Programming and Scripting 2 06-22-2006 10:57 AM
If a is windows gui ( client), b is a unix gui ( Server for a) and c is a shell scrip hchivukula UNIX for Dummies Questions & Answers 1 06-12-2005 09:34 AM
Execute an Oracle stored procedure from a shell scrip mh53j_fe Shell Programming and Scripting 1 06-03-2005 04:17 PM


All times are GMT -4. The time now is 08:47 PM.

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