1754875 Members
5507 Online
108827 Solutions
New Discussion юеВ

Please help!

 
SOLVED
Go to solution
Vande Matram
Occasional Contributor

Please help!

Hi guys!
This is probably the easiest question you have been asked...but I am just starting out in UNIX shell scripting and need your help with while loop.
What I want to do is say,
while not end of file filename
if .......
then ......
elif ......
then ......
fi
end
Can you please tell me the exact syntax of how to accomplish the above task? I am having rough time with this. Thank you so much guys!
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Please help!


This should get you started:

FILENAME=myfile

cat ${FILENAME} | while read X
do
if [ "${X}" = "Me" ]
then
echo "Yes"
else
echo "${X}"
fi
done
If it ain't broke, I can fix that.
Vande Matram
Occasional Contributor

Re: Please help!

:-) aaaah....finally! Thank you so much! You've been a great help! I will try your approach.
Steve Post
Trusted Contributor

Re: Please help!

here is another way (that looks weird).

exec 3while read X 0<3&
do
echo $X
done
3<&-

The X variable here is a line from the file, instead of a word.

So to be each line, each word.....
exec 3while read XLINE 0<3&
do
echo "line $XLINE"
for XWORD in $XLINE
do
echo "word $XWORD"
done
done
3<&-

hope it helps. Steve ^_^