bash SED 删除字符串之前的所有内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41591112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SED remove everything before string
提问by Damon
I have a plain Mail and i need to remove everything before Summary of client activity for the last 24 hours
i thought it would work best with sed.
我有一个普通的邮件,在Summary of client activity for the last 24 hours
我认为它最适合 sed之前,我需要删除所有内容。
I searched the internet but there it's just with a delimiter or something similar.
我在互联网上搜索过,但只有一个分隔符或类似的东西。
You have any ideas?
你有什么想法吗?
Part of the Mail:
部分邮件:
...(Personal Part of the Email)...
...
The following clients have no associated schedule
NodeDomainContact
-KABA-FILESYSTEM-
-USTICA-FILESYSTEM-
Summary of client activity for the last 24 hours
DomainNodenamePlatformTypeActivityData amountElapse timeAffectedFailedMedia wait
-FILESYSTEM-ABSYNTHE-Linux x86-64-XFS-
BACKUP-
337.5 MB-
00:00-
60-
0-
0
...
Desired Output:
期望输出:
Summary of client activity for the last 24 hours
DomainNodenamePlatformTypeActivityData amountElapse timeAffectedFailedMedia wait
-FILESYSTEM-ABSYNTHE-Linux x86-64-XFS-
BACKUP-
337.5 MB-
00:00-
60-
0-
0
...
回答by Kent
it is easy:
这很容易:
awk '/Summary of client activity for the last 24 hours/{p=1}p' file
Or sed:
或 sed:
sed -n '/Summary of client activity for the last 24 hours/,$p' file
Test with your email example with awk (sed cmd above has same output):
使用 awk 测试您的电子邮件示例(上面的 sed cmd 具有相同的输出):
kent$ cat f
...(Personal Part of the Email)...
...
The following clients have no associated schedule
NodeDomainContact
-KABA-FILESYSTEM-
-USTICA-FILESYSTEM-
Summary of client activity for the last 24 hours
DomainNodenamePlatformTypeActivityData amountElapse timeAffectedFailedMedia wait
-FILESYSTEM-ABSYNTHE-Linux x86-64-XFS-
BACKUP-
337.5 MB-
00:00-
60-
0-
0
...
kent$ awk '/Summary of client activity for the last 24 hours/{p=1}p' f
Summary of client activity for the last 24 hours
DomainNodenamePlatformTypeActivityData amountElapse timeAffectedFailedMedia wait
-FILESYSTEM-ABSYNTHE-Linux x86-64-XFS-
BACKUP-
337.5 MB-
00:00-
60-
0-
0
..
回答by nu11p01n73R
You can use sed address range to not print all lines from first to the pattern as
您可以使用 sed 地址范围不将所有行从第一个到模式打印为
$ sed -n '1, /Summary of client activity for the last 24 hours/!p;
DomainNodenamePlatformTypeActivityData amountElapse timeAffectedFailedMedia wait
-FILESYSTEM-ABSYNTHE-Linux x86-64-XFS-
BACKUP-
337.5 MB-
00:00-
60-
0-
0
...
To include the Summary...
line as well,
Summary...
还要包括该行,
$ sed -n '1, /Summary of client activity for the last 24 hours/!p; /Summary of client activity for the last 24 hours/p' test
Summary of client activity for the last 24 hours
DomainNodenamePlatformTypeActivityData amountElapse timeAffectedFailedMedia wait
-FILESYSTEM-ABSYNTHE-Linux x86-64-XFS-
BACKUP-
337.5 MB-
00:00-
60-
0-
0
...