Compare a file and insert


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare a file and insert
# 1  
Old 01-24-2011
Compare a file and insert

I have 2 files (A and B), Compare B with A and if the content matches based on a loop, overwrite those contents in A with B.

If B has something like below. The number '7658763276783' is an unique number to find out this group
HTML Code:
GS**342050359*
ST*820*3420122
REF*TN*7658763276783*TRACE NUMBER FROM
DTM*009*101207
N1*PR*
N1*PE* 19308540
RMR*TN*1190025555**192387.20*192387.20
RMR*TN*0123456666**1*1
DTM*009*101207
SE*000010*342050361
GE**342050359*
In A, I have to search the unique number and find the similar group starting with GS* and ending with GE*. A will be something like
HTML Code:
GS**342050359*
ST*820*3420122
REF*TN*7658763276783*TRACE NUMBER FROM
DTM*009*101207
N1*PR*
N1*PE* 19308540
RMR*TN*1190025555**192387.20*192387.20
RMR*TN*1234556668**1*1
SE*000010*3420122
GE**342050359*
GS**342032432*
ST*820*3243242
REF*TN*453248389879*TRACE NUMBER FROM
DTM*009*101207
N1*PR*
N1*PE* 19308540
RMR*TN*9749827983***172163*172613
SE*000010*3243242
GE**342032432*
And the output has to be something like below, where the contents in B has be overwritten in the relevant loop in A
HTML Code:
GS**342050359*
ST*820*3420122
REF*TN*7658763276783*TRACE NUMBER FROM
DTM*009*101207
N1*PR*
N1*PE* 19308540
RMR*TN*1190025555**192387.20*192387.20
RMR*TN*0123456666**1*1
DTM*009*101207
SE*000010*342050361
GE**342050359*
GS**342032432*
ST*820*3243242
REF*TN*453248389879*TRACE NUMBER FROM
DTM*009*101207
N1*PR*
N1*PE* 19308540
RMR*TN*9749827983***172163*172613
SE*000010*3243242
GE**342032432*
Not sure if this is possible, I need the right direction to go on this issue..
# 2  
Old 01-24-2011
After the operation, Will the record in B be identical to the one in A?
# 3  
Old 01-25-2011
No it will not be identical. The data in B has to be replaced based on the looping on file A
# 4  
Old 01-25-2011
Then I don't get what you're asking for.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. UNIX for Beginners Questions & Answers

Insert content from file 1 to file 2 in specific criteria meet

Hi , I'm looking for some code that can copy and paste form file1 to file2 with 2 criterial meet. file1: test "sp-j1" test "sp-j2" test "sp-j3" test "sp-j4" file2: sub Pre_Shorts1 (Status_Code, Message$) global Status !if Message$ <> "" then print... (3 Replies)
Discussion started by: kttan
3 Replies

3. Shell Programming and Scripting

Insert content of file before the first occurrence of a line starts with a pattern in another file

Hi all, I'm new to scripting.. facing some problems while inserting content of a file into another file... I want to insert content of a file (file2) into file1, before first occurrence of "line starts with pattern" in file1 file1 ====== working on linux its unix world working on... (14 Replies)
Discussion started by: Jagadeesh Kumar
14 Replies

4. Shell Programming and Scripting

Insert content of a file to another file at a line number which is given by third file

Hi friends, here is my problem. I have three files like this.. cat file1.txt ======= unix is best unix is best linux is best unix is best linux is best linux is best unix is best unix is best cat file2.txt ======== Windows performs better Mac OS performs better Windows... (4 Replies)
Discussion started by: Jagadeesh Kumar
4 Replies

5. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

6. UNIX for Dummies Questions & Answers

Shell script find word from one file and insert in another file

Hi, I am new to shell scripting. I need a bash shell scripts which search and grep a parameter value from input.txt file and insert it in between two semicolon of second line of output.txt file. For example The shell script search an IP address as parameter value from input.txt ... (2 Replies)
Discussion started by: sunilkumarsinha
2 Replies

7. Shell Programming and Scripting

compare three files and insert a blank line at each mismatch

i need to compare three files in unix a.txt b.txt c.txt 1 2 1 2 5 3 4 6 5 5 6 6 i need to insert a blank line in the file if i don't find a match and put the items at the same column if found a match The items in the files... (4 Replies)
Discussion started by: mad_man12
4 Replies

8. Shell Programming and Scripting

insert a header in a huge data file without using an intermediate file

I have a file with data extracted, and need to insert a header with a constant string, say: H|PayerDataExtract if i use sed, i have to redirect the output to a seperate file like sed ' sed commands' ExtractDataFile.dat > ExtractDataFileWithHeader.dat the same is true for awk and... (10 Replies)
Discussion started by: deepaktanna
10 Replies

9. Shell Programming and Scripting

awk script to compare and insert a line

Hi I want to compare a string at fixed position 10-20 for all the lines starting with 6. if they dont match it should take a copy of a line starting with 1 and insert it before the line starting with 6. How do i this? Please help Eg 1 test 1 765533 7643743 6 yes 3 5363653 373833 7... (9 Replies)
Discussion started by: appsguy616
9 Replies
Login or Register to Ask a Question