如何使用shell脚本在文本文件中插入单词

时间:2014-02-15 16:26:48

标签: shell

任何人都可以帮助我解决以下问题

我有一个以下格式的文本文件,我想在特定字段中插入一个单词,我想将该文件保存在shell脚本中,不要干扰文件中的任何内容。

例如:

cat sample.txt

name=xxxxxx

age=45

gender=femal

college=XXXXXX

class=b1

section=h2
像那样

我想代替XXXXX一些字。

有可能吗?

2 个答案:

答案 0 :(得分:1)

sed -i 's/college=.*/college=SOME WORD/' sample.txt

答案 1 :(得分:0)

另一个选择

sed -i '/^college=/ccollege=some word' sample.txt

结果

name=xxxxxx

age=45

gender=femal

college=some word

class=b1

section=h2
相关问题