[英]How to remove series of lines in a file on hp unix using awk or sed or grep
My report looks like: 我的报告如下:
Report B566 company name .................................... Page 1
Name address pin
John ny 1111
Dave ma 1112
.... .... ....
.... .... ....
.... .... ....
Report B566 company name .................................... Page 2
Name address pin
Barry CA 5111
This way i have around 100 pages, i want to get rid of repetitive headers. 这样,我大约有100页,我想摆脱重复的标题。 i need a command in such way that if "Report B566" is found in the file all of them along with the next 6 lines should be removed and the outfile should contain only the data.
我需要这样的命令:如果在文件中找到“ Report B566”,则应将所有它们连同接下来的6行一起删除,并且outfile应该仅包含数据。
I'm working on HP-UNIX box. 我正在使用HP-UNIX。 (ksh)
(ksh)
Thanks for your help. 谢谢你的帮助。
You can set a counter and print based on when the counter is true. 您可以设置一个计数器,并根据计数器为真的时间进行打印。
$ awk '/Report/{c=6}!(c&&--c)' file
John ny 1111
Dave ma 1112
.... .... ....
.... .... ....
.... .... ....
Barry CA 5111
Sed solution sed溶液
sed '/Report/,+4d' file
This removes the report line and the four following lines, it's a really simple command. 这将删除报告行和随后的四行,这是一个非常简单的命令。
This might work for you (GNU sed): 这可能对您有用(GNU sed):
sed -r '/Report/{G;/^(\S+\s+\S+\s).*\n\1/!{s/\n.*//;h;b};N;N;N;N;d}' file
Compare Report
lines to the previous one and if they are the same remove it and the next five lines. 将
Report
行与上一行进行比较,如果相同,则将其删除,并将其删除后五行。 If not the same store it and resume as usual. 如果存储的内容不同,请照常进行恢复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.