Linux中通过bash命令如何在文本文件前追加文本内容
2024-07-06
52
需求描述
在linux写bash脚本时,需要对一个文本文件进行修改,想在文件的前面添加一行,找了一下相关命令,可以使用echo, cat,sed命令实现,记录备忘,供参考。
实现方法
echo, cat命令组合
echo task goes here | cat - todo.txt temp mv temp todo.txt #方法1
echo -e task goes here\n$(cat todo.txt) todo.txt #方法2
echo task goes here | cat - todo.txt temp mv temp todo.txt #方法3
sed命令
sed -i 1s/^/task goes here\n/ todo.txt
更新于:2个月前赞一波!
相关文章
- git remote 命令详解
- git diff 命令详解
- git log 命令
- git branch 命令详解
- TP6.0命令行之自定义指令
- 微信小程序内容安全检测(敏感词、敏感图)
- TP6.0 自定义命令创建类文件
- Linux sed命令关键字匹配文件中整行的任意字符然后替换整行
- linux的Shell脚本中如何判断某个命令是否存在
- Linux中date命令如何格式化输出需要的时间格式
- vscode中自动将json格式的内容自动生成对应的代码
- 修改数据 update 命令
- Composer 使用缩略名调用命令
- 删除数据 delete、truncate 命令
- MySQL 添加数据 insert 命令及优化
- Linux中通过命令连接指定WiFi
- Linux 删除文件或目录 rm 命令
- composer list 查看命令
- 使用 Python 拆分文本文件的最快方法是什么?
- linux的shell脚本中如何在一个字符串中查找指定字符串是否存在
文章评论
全部评论