在线等待,用sed命令如何替换整行?

请问用sed命令如何替换整行?

例如file.txt为:
hello
world

如何替换为:
hello
boy

谢谢!!

---------------------------------------------------------------

不是一样吗?
sed 's/world/boy/' file.txt >new.txt
因为sed中它只是看字符流,不管它在一行中是什么位置。
---------------------------------------------------------------

用sed可以吗?我不知道。不过可以用awk
---------------------------------------------------------------

不知道这一行写着什么?那就是你知道要替换第几行,否则……
替换某一行用c,如:替换第二行为Hello, world:
sed -e '2c\
Hello, world' file.txt

---------------------------------------------------------------

sed 's/^.world.$/boy/g'

Published At
Categories with 服务器类
Tagged with
comments powered by Disqus