Compare the column 11 of file 1 with the 1st column of file2. The 1st column of file2 contains a prefix dpt. also. We need to compare file2 with file1 and in the output we should get all the values from file2 that are present in file1. We should not remove dpt. from the output. It will always be 8 characters in 1st column of file2 (e.g DPT.1072).
Thanks for your reply. I will try this. Only thing I am not sure is the prefix DPT. in file2. We want to compare two files after removing prefix DPT. but we do NOT want to remove DPT. from the output. Means in the comparsion command only we need to compare without DPT.---------May be at the time of comparsion something like substr(col1 of file2, 4,8)...........
file2
3308100100|Store Inventory Turns Without Gas(FT LEONARD WOOD MS)
0530100300|Total Markdowns(FT BRAGG MS - SOUTH)
4792999900|Productivity(TRAV AFB)
the file3 should be like this:
3308100100|C|20.83|21.87|22.91|04/APR/2009|2009|02|MAR|Store Inventory Turns Without Gas(FT LEONARD WOOD MS)
3308100100|C|18.74|19.67|20.61|04/APR/2009|2009|02|MAR|Store Inventory Turns Without Gas(FT LEONARD WOOD MS)
3308100100|C|741.50|778.58|815.65|04/APR/2009|2009|02|MAR|Store Inventory Turns Without Gas(FT LEONARD WOOD MS)
0530100300|C|38.26|40.17|42.08|04/APR/2009|2009|02|MAR|Total Markdowns(FT BRAGG MS - SOUTH)
you can see comparision is being done on column 1 of both the files...if column1 of file 1 matches with column 1 of file2 then we need to append column 2 of file 2 in the end of matching rows from file1............please let me know if it is possible or not?
while(<DATA>)
{
my @tmp=split("[|]",$_);
$hash{$tmp[10]}=1;
}
open $fh,"<","a.txt";
while(<$fh>){
my @tmp=split;
my @t1=split("[.]",$tmp[0]);
print if exists $hash{$t1[1]};
}
__DATA__
9000|9000|WW|1|1|SL|472|472|LC|2272|1072|MTY
9000|9000|WW|1|1|SL|470|470|MC|1270|1172|MPVT
9000|9000|WW|1|1|SL|472|472|LC|1072|1672|MBD
9000|9000|WW|1|1|SL|473|473|LF|1173|1173|MTY
Thanks vgersh99....I will start next thread as you suggested but one more help as it is related to this one only......if it had been a column 4 (instead of column 1)of file 1 and column 5 (instead of column 1)of file2 then how would we have written this command.