Replace data of a file with data from another file using shell scripting.

Dears,

I'm new to shell scripting and i was wondering if you can help me with following matter.
I have a file containing 400,000 records. The file contains two columns like:

00611291,0270404000005453
25262597,1580401000016155
25779812,1700403000001786
00388934,1200408000000880
25522814,7270401000008341
01840654,1860408000000921
. .
. .
. .

I also have another file containing 400,000 records with more or less following format:

01000101EBP 002     00019356
01000202EBP 002     0120401000000048            985010000019356
01000303EBP 002     0120401000000048            00019356

For example i want to replace 00019356 (from second file) with value 00611291 (from first file).

At the beginning i'm reading a string in specific line with fixed position and fixed length like:

awk 'NR==2 {print substr($0,21,8)}' TEST_sdi
awk 'NR==3 {print substr($0,21,49),substr($0,56,64)}' TEST_sdi
awk 'NR==4 {print substr($0,165,193),substr($0,195,201)}' TEST_sdi

First problem is, how i can read a string from 400,000 records and second how i can replace those values with values from first file, i suppose sed will do the job but could you please give me some more :)details.

Many thanks!! :slight_smile:

assuming the key is the record/line number from each file:

awk -F,  'FNR==NR{f1[FNR]=$1;next}{$2=f1[FNR]}1' file1 FS=' ' file2