-->

Thursday, May 30, 2013

To read a file in a loop


To read the file line by line use:


cat sample.txt | while read line; do echo $line; done 

To read the file element (word) by element you can use:


for word in `cat sample.txt`; do echo $word; done


or 

while read line; do echo $line; done  <  sample.txt


credit +Isaac Alonso 


No comments:

Post a Comment