Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Perl-Sensitive Sunglasses
 
PerlMonks  

Dealing with multiple input files at Command lLine

by ZWcarp (Beadle)
on Apr 18, 2012 at 15:03 UTC ( #965725=perlquestion: print w/ replies, xml ) Need Help??
ZWcarp has asked for the wisdom of the Perl Monks concerning the following question:

Ok so I asked a similar question so please forgive me.. but I think this one is different enough to warrant its own thread. I'm a bit confused about how to deal with multiple files at the command line.

Lets say file one is a list, and I want to print out every line in file 2 that matches the current element in the list file1. In a script you would do this by making a nested foreach loop and using arrays or you could do it by making a hash and then checking the hash.. How would one do this at command line (specifically dealing with 2 files ) ? Something like this where the file 2 lines only are piped in to the matching part:

 perl -walne'$h{$F[0]}.="$F[1] "; END{#Line from file2 here#=~/$h{$_}/&&print"$h{$_}"for keys%h}' file1.txt file2.txt

Comment on Dealing with multiple input files at Command lLine
Download Code
Re: Dealing with multiple input files at Command lLine
by Anonymous Monk on Apr 19, 2012 at 04:19 UTC

    How would one do this at command line (specifically dealing with 2 files )

    You wouldn't, you would write a program to do it

    This advice from someone who's written quite a few one-liners like you describe

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2014-04-17 01:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (437 votes), past polls