Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loops..

Status
Not open for further replies.

AdamCoombs

Technical User
May 22, 2002
51
GB
Hello,

Im trying to run this script,

#!/bin/ksh
OUTPUTFILE=`cat names.adam1`
for lines in $OUTPUTFILE
do
echo $lines
grep $lines bla bla bla
done

The OUTPUTFILE is a list of names.
Adam Coombs
Dave Jones
Gary Doe

that sort of thing..
but the output of $lines is supposed to be the entire line of the outputfile, ie: "Adam Coombs" but its comming out
Adam
Coombs
Dave Jones
Gary
Doe

how do i get it to do

Adam Coombs
Dave Jones
Gary Doe
????????

I have tried all the "`' with no joy!!!

many thanks
Adam
 
Adam, try putting double-quotes (") around your $lines variable when echoing it. HTH.
 
Tried that one...unfortunatly is not that simple!!
thanks for your help though...
SCRIPT
-------------------------------
#!/bin/ksh
set -x
#cat names1 | awk '{print $1,$2}' > names.adam

OTHERFILE='mail1'
OUTPUTFILE=`cat names.adam1`
for lines in $OUTPUTFILE
do
echo "$lines"

done
-----------------------------------
OUTPUT (debugged with set -x)

+ OTHERFILE=mail1
+ + cat names.adam1
OUTPUTFILE=Adam Coombs
John Doe
Paul Smith
Jim Jones
Barry Walk
+ echo Adam
Adam
+ echo Coombs
Coombs
+ echo John
John
+ echo Doe
Doe
+ echo Paul
Paul
+ echo Smith
Smith
+ echo Jim
Jim
+ echo Jones
Jones
+ echo Barry
Barry
+ echo Walk
Walk
 
For the "for comand" the separator is blank
you can try to use the read comand like this

exec 3</pathname/filename
while read -u3 lines
do
echo $lines

grep &quot;$lines&quot; bla bla bla ( don't forget double quotes )
done
 
Adam, found this previously posted by aigles (Jean Pierre). Seems to do the trick:

nCounter=1
while read newRecord
do
echo &quot;$newRecord&quot;
nCounter=`expr $nCounter + 1`
done < outputfile

Hope this helps.
 
Sorted, thats done the trick...
thanks for you help all....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top