用另一个文本文件中的文本替换行中的文本

时间:2015-03-04 15:30:05

标签: shell

请告诉我如何用另一个文件中的文本替换文件中的一组文字。

示例:在文件1中,条目为

Server: Hardcoded.large.net:5600
The above is the entry for the servers for HAXDTS.

文件2中的条目是,

Adhoc.large.net:5600
HAXDTSij

我需要使用File2中的条目替换条目“Hardcoded.large.net:5600”,并使用HAXDTS

替换HAXDTSij

该文件应修改为

Server:Adhoc.large.net:5600
The above is the entry for the servers for HAXDTSij

我该怎么做?

1 个答案:

答案 0 :(得分:1)

sed -i "s/Hardcoded/Adhoc/" <file1>

sed -i "s/.*HAXDTS/HAXDTSij/" <file1>

您应备份file1,以备将其还原。

如果您需要执行大量文件,请将其放入循环中。

相关问题