使用 sed 或 awk 在特定行号处插入一行 [英] Insert a line at specific line number with sed or awk

查看:35
本文介绍了使用 sed 或 awk 在特定行号处插入一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本文件,我需要用另一个脚本修改它以在第 8 行插入文本.

I have a script file which I need to modify with another script to insert a text at the 8th line.

要插入的字符串:Project_Name=sowstest,插入名为 start 的文件中.

String to insert: Project_Name=sowstest, into a file called start.

我尝试使用 awk 和 sed,但我的命令出现乱码.

I tried to use awk and sed, but my command is getting garbled.

推荐答案

sed -i '8i This is Line 8' FILE

在第 8 行插入

This is Line 8

进入文件FILE

-i 直接对文件 FILE 进行修改,不输出到 stdout,如 glenn jackman 的评论中所述.

-i does the modification directly to file FILE, no output to stdout, as mentioned in the comments by glenn jackman.

这篇关于使用 sed 或 awk 在特定行号处插入一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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