1. sed 首行添加内容
sed -i "1i 一串文字" a.txt
执行后,在a.txt文件的第一行插入"一串文字"
=================>
补充:
mac电脑这么搞:
sed -i '' '1i\
一串文字
' a.txt
//或brew install gnu-sed下载GNU的sed,终端中默认的是BSD的sed。
然后用gsed代替sed命令就行了,如果还是想用sed命令,可以设置别名:
alias sed=gsed
2. 在文件的指定行(n)插入指定内容:
`sed -i “niecho ‘test’” a.txt
执行后,在a.txt文件的第n行插入"test"
3. 最后一行添加
echo “123” >> a.txt