awk中的多行编辑

awk中的多行编辑,awk,multiline,Awk,Multiline,在上述格式中,我的记录分隔符是------ 我想删除所有单行记录,因此第一条记录应该删除,第二条记录应该保留 我想这很简单 MV: The Garden Murder Case (1936) ------------------------------------------------------------------------------- MV: The Garden of Allah (1936) BT: USD 2,200,000 ------------------------

在上述格式中,我的记录分隔符是------

我想删除所有单行记录,因此第一条记录应该删除,第二条记录应该保留

我想这很简单

MV: The Garden Murder Case (1936)
-------------------------------------------------------------------------------
MV: The Garden of Allah (1936)
BT: USD 2,200,000 
-------------------------------------------------------------------------------
我还尝试检查包含2个行尾字符的记录

BEGIN {RS="^[-]+$"}
  $0 !~ /^(BT|GR|OW|RT|AD)/ {next}
  1

两者都不起作用。

您不能在记录分隔符中使用
^
$
,因为它们是基于记录分隔符的记录的开始和结束

试试这个

BEGIN {RS="^[-]+$"}
  /$.+$/
  1 {next}
输出 如果要保留字段分隔符,则可以使用

MV: The Garden of Allah (1936)
BT: USD 2,200,000 
输入 输出
MV: The Garden of Allah (1936)
BT: USD 2,200,000 
awk -vRS="\n-+\n" -F"\n" 'NF>1{printf "%s%s",$0,RT}' file
MV: The Garden Murder Case (1936)
-------------------------------------------------------------------------------
MV: The Garden of Allah (1936)
BT: USD 2,200,000
-------------------------------------------------------------------------------
MV: The Garden Murder Case (1936)
-------------------------------------------------------------------------------
MV: The Garden of Allah (1936)
BT: USD 2,200,000
-------------------------------------------------------------------------------
MV: The Garden of Allah (1936)
BT: USD 2,200,000
-------------------------------------------------------------------------------
MV: The Garden of Allah (1936)
BT: USD 2,200,000
-------------------------------------------------------------------------------