http://www.perlmonks.org?node_id=965725

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

Replies are listed 'Best First'.
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