baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:

hi
This is probably a well know thing but somehow I missed it. Let say I have the following oneliner:
perl -lne '/^([^\t]*)\t/; $hash{$1}++}{print $_ foreach(keys %hash)' i +nfile.txt
My question is : What would be the simplest way to apply this one-liner to each file in my directory: ls dir | for each file execute: perl -lne '/^([^\t]*)\t/; $hash{$1}++}{print $_ foreach(keys %hash)' thnx

Replies are listed 'Best First'.
Re: Enclosing one-liner in a bigger loop - unix
by hippo (Archbishop) on Apr 24, 2015 at 08:56 UTC

    Just replace the filename with a wildcard such that your command line becomes

    perl -lne '/^([^\t]*)\t/; $hash{$1}++}{print $_ foreach(keys %hash)' *

    Is that all you were after?

      Ok, this is embarrassing. Thank you though... And the answer is yes

      UPDATE:

      Attempt to save the post.(Though I'll probably embarrass my self one more time)

      How would one do this if one would like to know what was matched in each file .
      Let the expected output be :

      file1: match match match file two: match match ...
      the same as grep function does. (Ano no, I don't want to use grep since I cannot hash)

        Look at $ARGV which contains the current file name.

        And you could avoid the eskimo kiss if you want with something like: perl -lne '/^([^\t]*)\t/ and not $h{$1}++ and print $1'