reading each line from a file

hi gurus.. i have a requirement like this...I need to read each line in a file and store it in a variable.. the file is li,e this. i would prefer to construct a loop for this.

1
2
3
4
5
6
7

i need something like this, while (i< last record in file)
x= the first record
do some stuff with x
(i=i+1)

read the next record in the next iteration.

thanks in advance

ragha81,
Here is one way of looping thru a file:

while read EachLine
do
   echo $EachLine
done < input_file

thanks a lot for your timely help buddy.. ur code worked the way i wanted!

another way for bash/csh

for i in `cat input_file` ; do
echo $i 
done

See 12 Ways to Parse a file

That script will strip leading and trailing spaces from the lines, and will treat backslashes as escape characters.

To prevent stripping spaces, set IFS to an empty string.

To prevent backslash interpretation, use the -r option:

while IFS= read -r EachLine