hi friends,
i have one problem in shell script.
i wrote for loop in sh.
i have one file called tmp in that list of lines are there like this.
suman
summeth
dfdfsdfa
dsfsdfsd
i am trying to read each line using for loop.
i want to read each line and write in to separate file.
my script is like this. but it is not working.
please help anyone.
for i in `cat $tmp`
do
echo $i
mv $i $var
csh script $i
done
lorcan
July 25, 2007, 11:58pm
2
Hope this is what you intended to do.
#! /bin/sh
for i in `cat $tmp`
do
echo $i
var=$i
#mv $i $var
csh script $i
done
thank u for your help.
but the script which u have given will only moves value to variable.
i.e in var.
but i want to write in a separate file.
regards
rajan
lorcan
July 26, 2007, 1:12am
4
var="$HOME/tmp_contents.txt"
echo $i >> $new_file
the above code is not working.
lorcan
July 26, 2007, 1:21am
6
No it should have been like
#! /bin/sh
var="$HOME/tmp_contents.txt"
rm -f $var
for i in `cat $tmp`
do
echo $i >> $var
csh script $i
done
i have one file called tmp in that list of lines are there like this.
suman
summeth
dfdfsdfa
dsfsdfsd
i am trying to read each line using for loop.
i want to read each line and write in to separate file.
while read line
do
echo $line
done < sourcefile > destfile
LisaS
July 26, 2007, 1:53am
8
do you need each line read to go into a different new file - or are you just copying them all into the same new file?
Hi Rajan,
I need more clear on ur issue. The mv command accept two file names. Refer your code in the script.
mv $i $var
$i - has fetched from the text file. You mean, that is a existing file name? Or, the value need to be written in a separate file? If so, then what is the name for the new file? Either it is a single file or multiple files?
Please clear.
-Sethu.