Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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?

share|improve this question

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.

this seems to be the best so far cat file | ( while read line do echo process $line done ) – James Andino Dec 9 '12 at 22:19
You like useless uses of cats, don't you? – gniourf_gniourf Dec 9 '12 at 22:28
And see also Understanding IFS – Gilles Dec 9 '12 at 23:06
i learned IFS the last time you recommended it =) – James Andino Dec 10 '12 at 6:16

1 Answer 1

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

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



  • using unix pipes have a cost, better avoid it for speed
share|improve this answer
hey thank you nice link that will help a small correction echo "$line" should be echo "$line" >> output =) – James Andino 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.