perl - How to compare two hashes -
i have 2 files have read 2 seperate hashes. first file has 2 columns , looks like:
123456789 11111 234567891 22222 345678912 33333
the second file has 1 column, looks like:
123456789 010124561 100324531
i want compare 2 hashes , whenever there match between first columns of 2 files, should print new file results of first column. have far...
#!/usr/bin/perl use sys::hostname; use lib "$env{home}/common/lib/perl"; use strict; use warnings; %oid; %oid2; %atom; %newline; $oid; $atom; @line = (); @line2 = (); @oid = (); @oid2 = (); $input = 'file.txt'; $input2 = 'file2.txt'; $output = 'outputfile.txt'; open (in, "<$input"); open (in2, "<$input2"); open (out, "+>$output"); $line (<in>) { chomp $line; @line = split /\t/, $line; push( @oid, $line[0] ); $oid{ $line[0] } = $line[0]; $atom{ $line[0] } = $line[1]; } $line2 (<in2>) { chomp $line2; @line2 = split /\t/, $line2; push( @oid2, $line2[0] ); $oid2{ $line2[0] } = $line2[0]; }
too code. know unix toolbox!
comm -12 <(cut -d' ' -f1 file1|sort) <(sort file2)
Comments
Post a Comment