1

Possible Duplicate:
How to loop over the lines of a file?

Let's say I cat a file and I want to run a bash command on each line and write each line as output.

How can I run a bash command on a single line the most succinct way?

cat something | lineBylineInplpace grep -E "spo" > &1

(I forget the standard descriptor symbol = / )

Should output the output of each line to the new file in place with the line it used for input.

I realize that this is very similar to awk. Is there a bash builtin kind of way to make this faster?

marked as duplicate by Gilles, Renan, jasonwryan, Michael Mrozek Dec 10 '12 at 1:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

The proper way to process a file line by lines is :

   while read -r line; do
       echo "$line"
    done < /path/to/file.txt

See http://mywiki.wooledge.org/BashFAQ/001

NOTE

  • using unix pipes have a cost, better avoid it for speed
  • hey thank you nice link that will help a small correction echo "$line" should be echo "$line" >> output =) – Arcabard Dec 9 '12 at 22:22
  • Free free to modify it to fit your needs. =) – Gilles Quenot Dec 9 '12 at 22:36
  • You missed setting IFS. See How to loop over the lines of a file? and other threads we've already had on this topic. – Gilles Dec 9 '12 at 23:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.