compare two files(column by column) in perl

August 9, 2011 at 01:11:07
Specs: Windows XP
Hi,

I am writing a comparator script, which comapre two txt files(column by column)

below are the precondition of this comparator

1)columns of file are not seperated
Ex.
file1.txt
8888812341181892
1243548895685687
8945896789897789

file2.txt
9578956789567897
8945789789567894
5789567895678967


where charactr 1-5 if field1
character 6-9 is file2 etc.

second file is also same structure. but the filed1 of file1 may differ from field1 of file2.

2) Field_Desc.csv
the position of fields is taken from third file (just call it Field_desc.csv)
from this file => we can take a field position and its length
Ex.
FIELD1|OFFSET|LENGTH

My question:

1) i am reading all files, but how to cut a specific column of a file(not line by line). I need entire column in a seperate variable.
Ex.

field1 of file1
88888
12435
89458

field1 of file2
95789
89457
57895

=> I am not getting above result.

2) now I will perform the diff command or check line1 of file1 is equal to line1 of file2. need result as below

Ex.
field1 of file1 field1 of file2 Result
88888 95789 "Error not equal value"
12435 89457 "Error not equal value"
89458 57895 "Error not equal value"

3) Script is executed as below

perl Script_compare.pl File1.txt File2.txt Filed_Desc.csv

and result must be writeen in another file "Result.log"


please help me. I was in second position "not able to cut the file in column basis.

thanks
vikash


See More: compare two files(column by column) in perl

Report •


#1
August 10, 2011 at 06:38:12
What have your tried?

What errors/warnings are you receiving?

As a starting point, you should read the following perldocs

perldoc -f substr
perldoc -f unpack
perldoc -f pack


Report •
Related Solutions


Ask Question