如何替换包含相同内容的行(LINUX)?

问题描述 投票:-1回答:1

如何替换包含相同内容的行

例如,我的行与随机事物并在该行中包含(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代码中

linux shell
1个回答
0
投票
gsed -i(或者在Linux上只是sed -i会有用吗?

$ 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-

© www.soinside.com 2019 - 2024. All rights reserved.