改变使用awk线 [英] change a line with awk

查看:125
本文介绍了改变使用awk线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林试图在使用awk文件一行的取代,例如:

Im trying to make a substitution of a single line in a file with awk, for example

更改此:

e1 is (on)

e2 is (off)

e1 is (on)

e2 is (on)

使用命令:

awk '/e2/{gsub(/off/, "on")};{print}' ~/Documents/Prueba > ~/Documents/Prueba

这使得替代,但文件结尾空白!

this makes the substitution but the file ends blank!

推荐答案

另一个答案,使用不同的工具(sed和使用-i(到位)标志)

Another answer, using a different tool (sed, and the -i (in place) flag)

sed -i '/e2/ s/off/on/' ~/Documents/Prueba

这篇关于改变使用awk线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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