Hi
i have the following code
for i in /backup/temp/rajesh/12Apr2012_South *.LOG
do
echo 'file name is $i'
done
this is not printing the value of variable from for loop what is wrong with the logic.
how can i assig the value fi for loop in vaiable e.g
for i in /backup/temp/rajesh/12Apr2012_South *.LOG
do
flnm = $i -- does it accept file name from for loop
echo 'file name is $i'
Please correct me
how to accept the value if $i in variable
I used double quote and it has printed
file name is /backup/temp/rajesh/12Apr2012_South
file name is *.LOG
instead all the file whose extension is .LOG
please help me to understand why it isso
Hi,
you need to escape a space between _South and *.LOG:
/backup/temp/rajesh/12Apr2012_South\ *.LOG
or wrap the path with double quote
no luck,
for i in "/backup/temp/rajesh/12Apr2012_South *.LOG"
do
flnm=$i
echo "file name is $flnm"
#sed "/s/filename/$i/g" control.ctl > newfilename
done
[oracle@reln-a00-mon104]>./run.sh
file name is /backup/temp/rajesh/12Apr2012_South *.LOG
I don't know what is missing since it is not able to print all the file names
for listing of all files you nedd to add
ls
I got it why it was not printing all the filename and instead it print the command as it is because the path of the file in the for loop is different than the path where this script is running.
Is there any way to run this scripts from any other directoy and the result should be same.
Please reply
@pokerino: No need for ls
, nor the $(...)
and the double quotes are incorrect...
for i in /backup/temp/rajesh/12Apr2012_South\ *.LOG
or if it is a directory that contains log files:
for i in /backup/temp/rajesh/12Apr2012_South/*.LOG
Or if you do not want the path in the file name:
cd /backup/temp/rajesh/12Apr2012_South
for i in *.LOG
Fine,
your code is working but it also prints all the files including .LOG which is not required.
it should list only .LOG file
---------- Post updated at 06:05 AM ---------- Previous update was at 05:54 AM ----------
Hi ,
Many thanks ,
it works now
/backup/temp/rajesh/12Apr2012_South/*.LOG - there is no space between South/ and *.LOG . befor i was putting one space.
Thanks
---------- Post updated at 06:16 AM ---------- Previous update was at 06:05 AM ----------
Hi
Just there is one mor issue , it print all the path name with the file name.
how can i avoid the path name and just show the file name
this doesn't work
cd /backup/temp/rajesh/12Apr2012_South
for i in *.LOG
Hi,
So sorry it is working.
many thanks
---------- Post updated at 06:25 AM ---------- Previous update was at 06:21 AM ----------
But can we do it without cd command as this will set the path forever in the script and if i have to manipulate the other file at the same time than i have to reset the path all the time
Sure...
for i in /backup/temp/rajesh/12Apr2012_South/*.LOG
do
echo "file name is ${i##*/}"
done
Hi
In the same code which is as below
cd /backup/temp/rajesh/12Apr2012_South
for i in *.LOG
do
flnm=$i
echo "file name is $flnm"
sed 's/filename/$flnm/g' /backup/temp/rajesh/prac/control.ctl
done
i have writeen sed which shold replace filename with the variable, which is not happening. i want to repalce control.ctl file content with $flnm where ever filename is present. so in this case it open the control file as many times as for loops operate.
Please help
---------- Post updated at 06:54 AM ---------- Previous update was at 06:52 AM ----------
Hi
echo "file name is ${i##*/}"
what ##* interpret to
---------- Post updated at 07:02 AM ---------- Previous update was at 06:54 AM ----------
Hi
Doesn't sed repalce the file content physically. as i have to reset the content with the value coming from for loop and then the changed file will be executed.
Please help