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

查看:99
本文介绍了如何在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天全站免登陆