Loop and append/write to the same file without ove

2019-06-12 21:28发布

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.

标签: shell loops
2条回答
三岁会撩人
2楼-- · 2019-06-12 21:48

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
查看更多
地球回转人心会变
3楼-- · 2019-06-12 21:52

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

查看更多
登录 后发表回答