Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: (thoughts on) Detect common lines between two files, one liner from shell

by merlyn (Sage)
on Dec 14, 2000 at 05:26 UTC ( #46545=note: print w/ replies, xml ) Need Help??


in reply to Re: (thoughts on) Detect common lines between two files, one liner from shell
in thread Detect common lines between two files, one liner from shell

Yeah, it's not an obfuscation by any means. Just a nice way to put together a lot of common features. In fact, I'd take it one step further to fulfill one additional monkey wrench thrown in after that posting was made: what if the line appears more than once in either fileA or fileB or both, but you still want only one copy of the line?

Well, the answer is just as straightforward. Remove the dollar from the regex! I'll leave that explanation as an exercise to the clever reader. {grin}

-- Randal L. Schwartz, Perl hacker


update: Bleh! My mistake, the dollar was added to handle this case! I knew I had needed to deal with multiple hits somehow.

Remind me never to post again. {grin}


Comment on Re: Re: (thoughts on) Detect common lines between two files, one liner from shell
Re^3: (thoughts on) Detect common lines between two files, one liner from shell
by Anonymous Monk on Dec 23, 2004 at 18:31 UTC
    This should also work for an arbitrary number of files, which AFAIK has no equivalent UNIX command. To show common lines in 4 files: perl -ne 'print if ($seen{$_} .= @ARGV) =~ /32+1+0$/' fileA fileB fileC fileD
      The generalized form would be (golfed down a bit) for any number of files
      perl -ne'BEGIN{$p.=-$_."+"for-@ARGV+1..-1;$p.=0}print if($s{$_}.=@ARGV +)=~/$p$/'

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2014-10-01 01:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (386 votes), past polls