使用sed/grep/awk删除所有内容,直到第一个空行

使用sed/grep/awk删除所有内容,直到第一个空行,sed,awk,grep,Sed,Awk,Grep,如果有人能帮我弄清楚怎么做,我将不胜感激 范例 block of //delete non-important text //delete important text //keep more important text //keep 如果空白行为空,将执行: sed '1,/^$/d' filename 或 输出 带awk的$sed'1,/^$/d': awk "BEGIN { x = 0 } /^$/ { x = 1} { if (x == 2) {

如果有人能帮我弄清楚怎么做,我将不胜感激

范例

block of            //delete
non-important text  //delete

important text      //keep
more important text //keep

如果空白行为空,将执行:

sed '1,/^$/d' filename

输出 带awk的
$sed'1,/^$/d':

awk "BEGIN { x = 0 } /^$/ { x = 1} { if (x == 2) { print } ; if (x == 1) { x = 2 } }" filename

另一个选项是
grep
(在线工作)

例如:

文件名包含以下行:

this is not implicated but important text
this is not important text
this is important text he says
not important text he says
not this it is more important text
过滤器包括:

grep -v "not imp" filename > newfilename
将使用以下3行创建新文件名:

this is not implicated but important text
this is important text he says
not this it is more important text

您必须选择一种模式,该模式将唯一地标识要删除的行。如果您使用
“重要文本”
,它将匹配所有行,而
“not imp”
仅匹配其中包含单词
“not imp”
的行。如果您希望在模式匹配中有更多的灵活性,请使用<代码> EGRP(或代码> GRP-E/COD>)。< /P>是空行空,还是可以包含空格?这样做是否更简单:“代码> AWK”{if(INITBULD)打印} /^ $ /{INITBULL=1 } < /COD>(这实际上可以全部在一行上)。
initblock
变量最初为零。
if
操作发生在所有行上,如果
initblock
不为零,则打印输入。
/^$/
模式匹配空行并设置
initblock=1
(意味着要删除的行的初始块已被看到,所有剩余的输入将被传递)。模式测试发生在打印之后,因此初始空白行不会被打印。@SiegeX,我怎么会错过它?谢谢
grep -v PATTERN filename > newfilename
this is not implicated but important text
this is not important text
this is important text he says
not important text he says
not this it is more important text
grep -v "not imp" filename > newfilename
this is not implicated but important text
this is important text he says
not this it is more important text