如何在Shell脚本中向文件添加行? [英] How can I add a line to a file in a shell script?

查看:1066
本文介绍了如何在Shell脚本中向文件添加行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在现有的CSV文件中添加一行标题,并在适当位置进行编辑.我该怎么办?

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

我想结束

column1, column2, column3
one,     two,     three

更改初始CSV输出不方便.

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.

推荐答案

这将在文件的开头添加自定义文本:

This adds custom text at the beginning of your file:

echo 'your_custom_escaped_content' > temp_file.csv
cat testfile.csv >> temp_file.csv
mv temp_file.csv testfile.csv

这篇关于如何在Shell脚本中向文件添加行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆