Reputation: 477
MV: The Garden Murder Case (1936)
-------------------------------------------------------------------------------
MV: The Garden of Allah (1936)
BT: USD 2,200,000
-------------------------------------------------------------------------------
In the above format my record separator is the line of ------
I want to drop all single line records so above the first record should drop and the 2nd should be kept.
Simple enough so I thought.
BEGIN {RS="^[-]+$"}
$0 !~ /^(BT|GR|OW|RT|AD)/ {next}
1
I also tried checking for a record that contains 2 end of line characters
BEGIN {RS="^[-]+$"}
/$.+$/
1 {next}
Neither worked.
Upvotes: 1
Views: 303
Reputation:
You can't use the ^
and $
in the Record separator as they are the start and end of records based on the record separator.
Try this
awk -vRS="\n-+\n" -F"\n" 'NF>1' file
MV: The Garden of Allah (1936)
BT: USD 2,200,000
If you want to retain the field separators then you can use
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
-------------------------------------------------------------------------------
Upvotes: 3