Okay, so I have this xml file. I need to replace every key value with a value from another file (txt). Both files are sorted so line 20 i.e inside the xml   <word key=ACTIVE group=Service application value=testvalue1/>Within my second file, on line 20 will betestvalue2I am looking for something which will change the value from testvalue1 to testvalue2
Large replace in XML
text processing;scripting;cat;xml
This should work.We load the new values file, and then we process then xml file by replacing old value with new value using line number as the key.awk 'FNR==NR{a[FNR]=$0;next}{$NF=gensub(/value=.*\/>/,value=\a[FNR]\\/>,g,$NF);print}' file2 file#OR working with regex groups:awk 'FNR==NR{a[FNR]=$0;next}{$NF=gensub(/(value=)(.*)(.+)/,\\1a[FNR]\\3,g,$NF);print}' file2 fileTesting:$ cat file<word key=ACTIVE group=Service application value=testvalue1/>                                                                                                             <word key=ACTIVE group=Service application value=testvalue2/>                                                                                                             <word key=ACTIVE group=Service application value=testvalue3/>                                                                                                             <word key=ACTIVE group=Service application value=testvalue4/><word key=ACTIVE group=Service application value=/>$ cat file2newvalue1newvalue2newvalue3newvalue4                                                                                                                          newvalue5$ awk 'FNR==NR{a[FNR]=$0;next}{$NF=gensub(/value=.*\/>/,value=\a[FNR]\\/>,g,$NF);print}' file2 file<word key=ACTIVE group=Service application value=newvalue1/><word key=ACTIVE group=Service application value=newvalue2/><word key=ACTIVE group=Service application value=newvalue3/><word key=ACTIVE group=Service application value=newvalue4/><word key=ACTIVE group=Service application value=newvalue5/>