Skip to main content
added 153 characters in body
Source Link
George Vasiliou
  • 8.1k
  • 3
  • 24
  • 43

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=")(.*)(".+)/,"\\1"a[FNR]"\\3","g",$NF);print}' file2 file

Testing:

$ 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 file2
newvalue1
newvalue2
newvalue3
newvalue4                                                                                                                          
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"/>

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

Testing:

$ 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 file2
newvalue1
newvalue2
newvalue3
newvalue4                                                                                                                          
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"/>

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=")(.*)(".+)/,"\\1"a[FNR]"\\3","g",$NF);print}' file2 file

Testing:

$ 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 file2
newvalue1
newvalue2
newvalue3
newvalue4                                                                                                                          
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"/>
deleted 827 characters in body
Source Link
George Vasiliou
  • 8.1k
  • 3
  • 24
  • 43

This should work, We.
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=")(.+)(".+)*"\/>/,"\\1"a[FNR]"\\3""value=\""a[FNR]"\"\/>","g",$NF);print}' file2 file
$ 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 file2
newvalue1                                                                                                                                                                       
newvalue2                                                                                                                                                                       
newvalue3                                                                                                                                                                       
newvalue4                                                                                                                                                                       
newvalue5

$ awk 'FNR==NR{a[FNR]=$0;next}{$NF=gensub(/(value=")(.+)(".+)*"\/>/,"\\1"a[FNR]"\\3""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="newvalue4"value="newvalue5"/>

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=")(.+)(".+)/,"\\1"a[FNR]"\\3","g",$NF);print}' file2 file
$ 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"/>                                                                                                             

$ cat file2
newvalue1                                                                                                                                                                       
newvalue2                                                                                                                                                                       
newvalue3                                                                                                                                                                       
newvalue4                                                                                                                                                                       

$ awk 'FNR==NR{a[FNR]=$0;next}{$NF=gensub(/(value=")(.+)(".+)/,"\\1"a[FNR]"\\3","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"/>

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
$ 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 file2
newvalue1
newvalue2
newvalue3
newvalue4                                                                                                                          
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"/>
added 131 characters in body
Source Link
George Vasiliou
  • 8.1k
  • 3
  • 24
  • 43

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.

This should work:

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.

Source Link
George Vasiliou
  • 8.1k
  • 3
  • 24
  • 43
Loading