Reputation: 21
I have a file that contains multiple entries. the entries are seperated by -- I want to remove all lines between this pattern if a certain phrase is not found within. Example:
--
Company
Street
Zip Code
Country
--
If Country is not found between -- and -- remove the complete block
Thanks in advance :)
Upvotes: 0
Views: 564
Reputation: 6204
Perhaps the following will be helpful:
use strict;
use warnings;
local $/ = '--';
print $/;
while (<>) {
print if /\bCountry\b/;
}
Usage: perl script.pl dataFile [>outputFile]
Data:
--
Company
Street
Zip Code
Elephant
--
Company
Street
Zip Code
Country
--
Company
Street
Zip Code
Goat
--
Company
Street
Zip Code
Country
--
Output:
--
Company
Street
Zip Code
Country
--
Company
Street
Zip Code
Country
--
Upvotes: 1