pogibas
pogibas

Reputation: 28339

Loop and append/write to the same file without overwriting

for num in {1..5}
do
perl simulate.pl file.txt file2.txt > output.txt
done

But my output is overwritten every time. I know their should be some kind of a simple answer to this which I don't know.

Upvotes: 0

Views: 4840

Answers (2)

ganesshkumar
ganesshkumar

Reputation: 1377

Use >> to concat the contents into a file. > will overwrite the file every time you write into it.

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798686

Either append at each iteration, or overwrite at the end.

> output.txt
for num in {1..5}
do
  perl simulate.pl file.txt file2.txt >> output.txt
done

for num in {1..5}
do
  perl simulate.pl file.txt file2.txt
done > output.txt

Upvotes: 7

Related Questions