Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: to delete a set of specific lines in a file (GOLF)

by ccn (Vicar)
on Dec 05, 2008 at 10:57 UTC ( [id://728253]=note: print w/replies, xml ) Need Help??


in reply to to delete a set of specific lines in a file

#!/usr/bin/perl -- # filter.pl use strict; use warnings; die "Usage: perl filter.pl pe_real_sample.txt > last.output\n" unless @ARGV; my %seen; my @ary; # push into @ary every line which have not be seen yet while (my $line = <>) { $line =~ /[fr] / or die "Can't parse line: $line"; my $key = $` . $'; push(@ary, [$line, $key]) unless $seen{$key}++; } # print all lines from @ary having $seen only once print $_->[0] foreach grep {$seen{$_->[1]} < 2} @ary;

This script can be written more shortly:

#!/usr/bin/perl -n /[fr] /, $s{$`.$'}++ || push @a, [$_,$`.$'] }{ $s{$_->[1]}<2 && print +$_->[0] for @a

or even:

#!/usr/bin/perl -n /f|r/,$s{$`.$'}++,push@a,[$_,$`.$']}{$s{$$_[1]}<2&&print$$_[0]for@a

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://728253]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-19 08:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found