0

我有一个文件,我想搜索具有特定世界的行并在其末尾附加一个句子我该怎么做?

4

1 回答 1

1

cat test.txt |sed 's/searchString/&addedString/' > new.txt

“&”指的是匹配的字符串。这是真实的例子

qifei@qifei] cat test.txt                                                                                                                                                                                     ~
aaaa
bbbb
cccc
aaaa
qifei@qifei] cat test.txt |sed 's/aaaa/&bbbb/' > new.txt                                                                                                                                                                                  ~
qifei@qifei] cat new.txt                                                                                                                                                                                                                  ~
aaaabbbb
bbbb
cccc
aaaabbbb
于 2012-07-03T10:35:46.960 回答