小编Jos*_*osh的帖子

在文件中查找一行,并在bash中添加一行到行尾

如何识别具有特殊模式的行开头并在行尾添加一些内容?

如果尚未附加应添加的模式

假设我想通过开头的模式在主机文件中找到一个特定的行,可能是ip-address,也可能是行上方的注释

一个例子可能是:

#This is your hosts file

127.0.0.1 localhost linux 

#This is added automatically 

192.168.1.2 domain1. com 

#this is added automatically to 

192.168.1.2 sub.domain1.com www.domain1.com
Run Code Online (Sandbox Code Playgroud)

当你找到我告诉你的IP时,我如何告诉bash.去结束并添加一些东西

或其他情况

当bash找到评论时 #This is added automatically

往下走2,然后到最后一行添加一些东西

你看我是初学者,并且没有任何想法在这里使用什么以及如何使用.是由sed解决?或者这可以用grep完成吗?我必须学习AWK吗?

linux bash file-io sed

4
推荐指数
1
解决办法
7493
查看次数

标签 统计

bash ×1

file-io ×1

linux ×1

sed ×1