Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^4: find common data in multiple files

by mao9856 (Sexton)
on Dec 31, 2017 at 06:18 UTC ( #1206468=note: print w/replies, xml ) Need Help??


in reply to Re^3: find common data in multiple files
in thread find common data in multiple files

Hi BR, I tried this code using it as follow:

$ perl test.pl *.txt

And it is giving output:

$VAR1 = [];

Please help me understand how should it work. Thank you in advance

Replies are listed 'Best First'.
Re^5: find common data in multiple files
by afoken (Abbot) on Dec 31, 2017 at 11:57 UTC

    I tried this code using it as follow:

    $ perl test.pl *.txt

    And it is giving output:

    $VAR1 = [];

    Are you running the script in the directory containing the *.txt files?

    What operating system are you using? If you are on Windows, there are some minor differences to Unix that prevent *.txt from being expanded to a list of files. In that case, add the following line to the perl script, right after "use warnings;":

    use Win32::Autoglob;

    (See Re^3: Perl Rename for details why this is needed.)

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re^5: find common data in multiple files
by thanos1983 (Vicar) on Jan 02, 2018 at 09:49 UTC

    Hello mao9856

    I think your question has already being answered by fellow Monk afoken. Fo me in UnixOS it looks that it is working fine, see sample of code bellow. For any reason if the script is not working on your OS update us and provide more information so we can assist you.

    Sample of dir:

    $ ls -la total 36 drwxr-xr-x 2 tinyos tinyos 4096 Jan 2 10:42 . drwxr-xr-x 5 tinyos tinyos 4096 Jan 2 10:41 .. -rw-r--r-- 1 tinyos tinyos 97 Jan 2 10:41 File1.txt -rw-r--r-- 1 tinyos tinyos 85 Jan 2 10:41 File2.txt -rw-r--r-- 1 tinyos tinyos 74 Jan 2 10:41 File3.txt -rw-r--r-- 1 tinyos tinyos 651 Jan 2 10:42 test.pl

    Sample of code:

    $ perl test.pl *.txt $VAR1 = [ 'ID157 TSR11', 'ID121 ABC14', 'ID122 EFG87' ];

    Hope this helps, Best Regards (BR).

    Seeking for Perl wisdom...on the process of learning...not there...yet!

      Hello Thank you for your time. I am using Linux Ubantu 16.04. Here is sample of dir

      $ ls -la total 272 drwxrwxr-x 2 meetal meetal 4096 Jan 3 12:06 . drwxrwxr-x 3 meetal meetal 4096 Jan 3 11:54 .. -rw-rw-r-- 1 meetal meetal 20188 Jan 3 11:54 4_os_10.txt -rw-rw-r-- 1 meetal meetal 14225 Jan 3 11:54 4_os_11.txt -rw-rw-r-- 1 meetal meetal 20788 Jan 3 11:54 4_os_12.txt -rw-rw-r-- 1 meetal meetal 3217 Jan 3 11:54 4_os_13.txt -rw-rw-r-- 1 meetal meetal 13845 Jan 3 11:54 4_os_14.txt -rw-rw-r-- 1 meetal meetal 1117 Jan 3 11:54 4_os_15.txt -rw-rw-r-- 1 meetal meetal 1929 Jan 3 11:54 4_os_16.txt -rw-rw-r-- 1 meetal meetal 15223 Jan 3 11:54 4_os_17.txt -rw-rw-r-- 1 meetal meetal 2020 Jan 3 11:54 4_os_18.txt -rw-rw-r-- 1 meetal meetal 14866 Jan 3 11:54 4_os_19.txt -rw-rw-r-- 1 meetal meetal 3068 Jan 3 11:54 4_os_1.txt -rw-rw-r-- 1 meetal meetal 16040 Jan 3 11:54 4_os_20.txt -rw-rw-r-- 1 meetal meetal 10557 Jan 3 11:54 4_os_2.txt -rw-rw-r-- 1 meetal meetal 10653 Jan 3 11:54 4_os_3.txt -rw-rw-r-- 1 meetal meetal 6558 Jan 3 11:54 4_os_4.txt -rw-rw-r-- 1 meetal meetal 18823 Jan 3 11:54 4_os_5.txt -rw-rw-r-- 1 meetal meetal 5934 Jan 3 11:54 4_os_6.txt -rw-rw-r-- 1 meetal meetal 17570 Jan 3 11:54 4_os_7.txt -rw-rw-r-- 1 meetal meetal 7785 Jan 3 11:54 4_os_8.txt -rw-rw-r-- 1 meetal meetal 13825 Jan 3 11:54 4_os_9.txt -rw------- 1 meetal meetal 12288 Jan 3 11:54 .inna.pl.swp -rw-rw-r-- 1 meetal meetal 651 Jan 3 11:54 test.pl

      And output i get

      $ perl test.pl *.txt $VAR1 = [];
      Regards mao9856

        Hello again mao9856,

        Can you cat -A 4_os_10.txt, I would like to see all the characters format of your file. It looks it is not matching the sample of DATA that you provide us. Also try to use as @ARGV a few files, for example 4_os_10.txt and 4_os_11.txt if you know that they contain even a single line in common.

        Also there is a great answer Re: find common data in multiple files from fellow Monk BillKSmith that is using the module setop and it is simplified a lot. Sample of code on how to run the script Re^2: find common data in multiple files.

        Give it a try and let us know for both cases, BR.

        Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1206468]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2018-04-24 07:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?