如何替换包含相同内容的行
例如,我的行与随机事物并在该行中包含(email)我想用该行中包含它的电子邮件替换所有行-所有电子邮件将以(abuse @。*)
开头aaaaaaaaaaaaaa [email protected]
-random lines with no email-
bbbbbbbbbbbbbb [email protected]
-random lines with no email-
cccccccccccccc [email protected]
-random lines with no email-
我的输出必须是
email: [email protected]
-random txt with no email-
email: [email protected]
-random txt with no email-
email: [email protected]
-random txt with no email-
因此它搜索行的前有(滥用@。*)。 [email protected]获取电子邮件,然后删除该行并放入电子邮件:[email protected]而不是该行
在shell代码中
$ cat substitute.txt
aaaaaaaaaaaaaa [email protected]
-random lines with no email-
bbbbbbbbbbbbbb [email protected]
-random lines with no email-
cccccccccccccc [email protected]
-random lines with no email-
$ cat substitute.txt | gsed -s "s/.*\(abuse\)/email: \1/"
email: [email protected]
-random lines with no email-
email: [email protected]
-random lines with no email-
email: [email protected]
-random lines with no email-
$ gsed -i.bak -s "s/.*\(abuse\)/email: \1/" substitute.txt
$ cat substitute.txt
email: [email protected]
-random lines with no email-
email: [email protected]
-random lines with no email-
email: [email protected]
-random lines with no email-