How can I add a line to a file in a shell script?

2020-02-07 23:20发布

I want to add a row of headers to an existing CSV file, editing in place. How can I do this?

echo 'one, two, three' > testfile.csv

and I want to end up with

column1, column2, column3
one,     two,     three

Changing the initial CSV output is out of my hands.

Any standard command will do. The important thing is the file is edited in place, and the line is inserted at the beginning of the file.

标签: linux shell sed
7条回答
我只想做你的唯一
2楼-- · 2020-02-07 23:59

Add a given line at the beginning of a file in two commands:

cat <(echo "blablabla") input_file.txt > tmp_file.txt
mv tmp_file.txt input_file.txt
查看更多
登录 后发表回答