输入文件有很多重复的文本块(用关键字划分:"块"开头和结尾)。我如何只打印那些不包含" NoGrade" ? sed或awk比pcgreg,perl更好(我已经可以在其中创建解决方案。)
对问题的补充 - >另外,如何避免匹配输出的重复?
输入文件(带有重复的文本块):
Blocks
GradeA
GradeZ
NoGrade
Blocks
GradeA
GradeB
GradeC
GradeA
Blocks
GradeD
GradeS
GradeE
NoGrade
Blocks
GradeX
GradeY
GradeZ
Blocks
GradeA
GradeB
GradeC
GradeA
Blocks
输出:
Blocks
GradeA
GradeB
GradeC
GradeA
Blocks
GradeX
GradeY
GradeZ
Blocks
答案 0 :(得分:2)
awk -vRS='Blocks' '!/NoGrade/{printf "%s",$0 RT}' file
Blocks
GradeA
GradeB
GradeC
GradeA
Blocks
GradeX
GradeY
GradeZ
Blocks