Skip to main content
1 of 4
George Vasiliou
  • 8.1k
  • 3
  • 24
  • 43

This should work:

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"/>                                                                                                             

$ 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"/>
George Vasiliou
  • 8.1k
  • 3
  • 24
  • 43