I need to some strings in a file in the following fashionOld file:Real/Test1Real/Test1Real/Test2Real/Test3Real/Test3Real/Test4New File:Real/Test1  a1 b1 c1 d1Real/Test1  a1 b1 c1 d1Real/Test2  a2 b2 c2 d2Real/Test3  a3 b3 c3 d3Real/Test3  a3 b3 c3 d3Real/Test4  a4 b4 c4 d4I have an intermediate file which has the old string in the column 1 and then the new string, something like this.Test1 a1 b1 c1 d1Test2 a2 b2 c2 d2Test3 a3 b3 c3 d3Test4 a4 b4 c4 d4Could anyone please help with this?With my very primitive knowledge, I tried following:(while read n1 n2 do set n1 n2 sed -i s/$n1/$n1 $n2/g old > final done)where old and intermediate inputs are the content mentioned above.Thanks a lot !
replace string in a loop
awk;sed;perl
perl -lne '   @ARGV and $h{$1}=s/(\S+)//r,next;   s|/(\S+)\K|$h{$1}|;print;' intermediate.file old.fileResultsReal/Test1 a1 b1 c1 d1Real/Test1 a1 b1 c1 d1Real/Test2 a2 b2 c2 d2Real/Test3 a3 b3 c3 d3Real/Test3 a3 b3 c3 d3Real/Test4 a4 b4 c4 d4ExplanationUsing the intermediate file (@ARGV is > 0) we populate the hash using the first field as the key and the remaining fields as the corresponding value.When we process the old file (@ARGV = 0), we look at the string after the slash and use that to pullup the hash value and put it back in the current line.