Awk to perl conversion

I have a directory full of files containing entries like:

FAKE ORGANIZATION
799 S FAKE AVE
Northern Blempglorff, RI 99xxx


                                                                      01/26/2011
     These items are being held for you at the location shown below each one.
     IF YOU ASKED THAT MATERIAL BE MAILED TO YOU, PLEASE DISREGARD THIS NOTICE.

     The Waltons. The complete  DAXXXX12118198
     Pickup at:CHUPACABRA LOCATION                                 02/02/2011







                                                  GRIMLY, WILFORD
                                                  29 FAKE LANE
                                                  S. BLEMPGLORFF RI  99XXX

I need to delete all records with an expression Pickup at:CHUPACABRA LOCATION.

The problem with the record separator : I can not touch the formatting of the input file - it must be saved as is. Each entry is split into approximately 40+ new lines.

Here are some awk (this works):

BEGIN { 
    RS="\n\n\n\n\n\n\n\n\n+" 
    FS="\n"
}
!/CHUPACABRA/{print $0}

My hit with perl:

perl -a -F\n -ne '$/ = "\n\n\n\n\n\n\n\n\n+";$\ = "\n";chomp;$regex="CHUPACABRA";print $_ if $_ !~ m/$regex/i;' data/lib51.000

Nothing returns. I am not sure how to specify a "field separator" in perl, except for the command line. I tried the a2p utility - without cubes. For the curious, here is what it produces:

eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z
            # process any FOO=bar switches

#$FS = ' ';     # set field separator
$, = ' ';       # set output field separator
$\ = "\n";      # set output record separator

$/ = "\n\n\n\n\n\n\n\n\n+";
$FS = "\n";

while (<>) {
    chomp;  # strip record separator
    if (!/CHUPACABRA/) {
    print $_; 
   }   
}

This should work under someone windows window, otherwise I will stick with awk.

Thank!

Buboff

EDIT (SOLVED) **

Thank you crowd! Here's the (working) version of the perl script (a2p output adjusted):

eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z
            # process any FOO=bar switches

#$FS = ' ';     # set field separator
$, = ' ';       # set output field separator
$\ = "\n";      # set output record separator

$/ = "\n"x10;
$FS = "\n";

while (<>) {
    chomp;  # strip record separator
    if (!/CHUPACABRA/) {
    print $_; 
    }   
}

CPAN, / perl-ish. !

+3
3

Perl , . perlvar doc :

: $/ , . awk -.: -)

, , $/="\n" x 10 - :

perl -a -F\n -ne '$/="\n"x10;$\="\n";chomp;$regex="CHUPACABRA";
       print if /\S/ && !m/$regex/i;' data/lib51.000

/\S/ &&, , 20 .

, Cygwin awk Windows?

+2

() , gawk

0

Did you know that Perl comes with a program called a2p that does exactly what you described in your name?

And if you have Perl on your computer, the documentation for this program already exists:

C> perldoc a2p

My own suggestion is to get the Llama book and learn Perl anyway. Despite what the Python people say, Perl is a great and flexible language. If you know shell, awk and grep, you will understand many of Perl constructs without any problems.

0
source

Source: https://habr.com/ru/post/1788072/


All Articles