Posted By

miklophone on 09/02/06


Tagged

zsh


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

hloo
nitehawk
iTony


Loop through lines of a text file


 / Published in: Bash
 

  1. for i in $(cat example.txt); do echo $i; done
  2.  
  3. for i (`cat example.txt`) echo $i
  4. # (Zsh only)

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: linuxtrek on October 18, 2009

In BASH, this is problematic when the line has text delimited by white space. Example: root@casc-tds-nas:~# cat /tmp/test first second third fourth root@casc-tds-nas:~# for i in $(cat /tmp/test); do echo "line: $i"; done line: first line: second line: third line: fourth

You need to login to post a comment.