views:

146

answers:

2

i have two files ...

file1:

002009092312291100098420090922111
010555101070002956200453T+00001190.81+00001295.920010.87P
010555101070002956200449J+00003128.85+00003693.90+00003128
010555101070002956200176H+00000281.14+00000300.32+00000281

file2:

002009092410521000098420090709111
010560458520002547500432M+00001822.88+00001592.96+00001822
010560458520002547500432D+00000106.68+00000114.77+00000106

in both files in every record starting with 01....the string from 3rd char to 25th char..i.e upto alphabet is the key... based on this key..i have to compare two files .....and if there is any record matching in file 2...then i have to replace that record in file1...or else append it if it wont match....

please help ASAP

+1  A: 

Well, this is a fairly unspecific (and basic) programming question. We'll be better able to help us if you explain exactly what you did and where you got stuck.

Also, it looks a bit like homework, and people are wary of giving too much help on homework problems, as it might look like cheating.

To get you started:

  • I'd recommend Perl to solve this, but awk or another scripting language will also do. I'd recommend against sh/bash, as they are weak on text manipulation; also combining grep et al will become rather cumbersome.
  • First write a Perl program that filters records starting with 01. Then extract the key and put it into a hash (a Perl structure). Then output a new, combined file as required.

Feel free to edit your question if you are still having trouble.

sleske
A: 

Using awk get the fields from 3-25 but doing sth like awk -F "" '/^01/{print $1}' file_name | cut -c 3-25 and match the first two fields with 01 from both files and get all the lines in two different buffers and compare both the buffers using for line in ina shell script.when ever the line in 2nd buffer matches the 1st one grep the line in 2nd buffer in ist file and replace the line in ist file with the line in second.this seems to be a home work.and u need to work a bit around the logic.

Vijay Sarathi