Perl script to match text in different files

We need a simple Perl script.

Basically this is what needs to be done:

Each line in file 1 must be matched against those in the file 2 and inserted into file 2 immediately after the closest match.

Format of the files:

File 1 "Newdata.txt" is a list of addresses. All lines in this file contain one to four segments of text. Each segment is separated by a comma. Some segments contain 3 segments and others contain all 4.

Here is an example:


Segment 1: Format is LOCATION/INSTITUTION NAME. Maximum length of this segment is 51 characters

Segment 2: Maximum length is 30 characters

Segment 3: Maximum length is 20 characters

Segment 4: Maximum length is 20 characters

This file is not sorted in any order and may be sorted if necessary.

File 2 "Database.txt"

This is a quite large file with more than 200,000 lines sorted by different address groups. Each address group is separated by a blank line and the first line of the each group ends with a colon and a letter code with one to three characters. All the other lines are in the same format as those in Newdata.txt.

This is what needs to be done in detail:

For nearly all the lines in [url removed, login to view] file, there is almost an identical line in the Database.txt. However, the match in the database file may contain only 19 characters (instead of 20) for segments 3 and 4.

Therefore, the Perl script should match:

segment 1 exactly as it is in both files

segment 2 exactly as it is in both files

segment 3, if there is one, up to the first 19 characters in both files

segment 4, if there is one, up to the first 19 characters in both files

Once the match is found, the line should be inserted immediately after the closest match in the [url removed, login to view] and must be removed from the Newdata.txt. Those not matched are left in Newdata.txt.

Also, whenever a line is inserted into the [url removed, login to view] please mark it with * , preferably at the beginning of the line, so we can check the accuracy of the script.

Please make sure that the Perl script will not alter the existing data or the order of each line in Database.txt.

I have included the two sample files and the first 11 lines in "Newdata.txt" do have a match in "Database.txt". For example, the line 1 in [url removed, login to view] matches the line 3 in [url removed, login to view], except for the last character in segment 3.

Beceriler: Perl

Daha fazlasını gör: perl match text file, perl match line, perl match file, match text file perl, match file perl, perl search file, perl match text, match files perl, perl match, perl script match files, perl script match text different files, perl match files, perl match line file, perl script match, perl match text files, perl search text file, perl script match file, match text perl, script match text, perl match script

İşveren Hakkında:
( 6 değerlendirme ) Canberra, Australia

Proje NO: #130764



Can do it easy

1 gün içinde %selectedBids___i_sum_sub_4%%project_currencyDetails_sign_sub_5% USD
(99 Değerlendirme)

Bu iş için 8 freelancer ortalamada $60 teklif veriyor


I have more than 7 years of perl programming experience, so this is not a difficult task at all. With best regards, Gaspar Chilingarov

in %bids___i_period_sub_35% gün içinde100%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(13 Değerlendirme)

should be a fairly easy task to accomplish. - Mickalo

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(3 Değerlendirme)

Good job for perl programmer.

in %bids___i_period_sub_35% gün içinde50%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(11 Değerlendirme)

Dear Sir, I am experienced perl developer. I have already completed a number perl jobs successfully. I have gone through your given project description. I can provide the solution in one day.

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(11 Değerlendirme)

Hello, I'm ready to start right now

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(3 Değerlendirme)

details on pm!

in %bids___i_period_sub_35% gün içinde40%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(0 Değerlendirme)

This is an easy task.

in %bids___i_period_sub_35% gün içinde100%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(0 Değerlendirme)