I have a file with two lines like:XXXXXXX20170412,bu.1519=1,bu.1124=2,bu.1284=3,bu.1767=13,bu.1869=15,bu.1784=16,bu.1473=32,bu.1264=43,bu.1758=96,bu.1649=122,bu.1345=140,bu.1268=215,bu.1246=516,bu.1876=601,XXXXXXX20170413,bu.1123=1,bu.1767=27,bu.1784=32,bu.1473=57,bu.1869=41,bu.1264=91,bu.1284=54,bu.1758=191,bu.1268=387,bu.1345=319,bu.1649=322,bu.1246=1199,bu.1876=1383,I want to get all strings exist in the first line (starting with string between , and= ) and not existing in the last line and append them to the end of the last line.
compare two lines in a file and modifythe last one
text processing;scripting
Form a hash %h whose keys are strings between , and =. This is formed only for the first line. Then on the second line, we search whether these keys are present in the 2nd line and collect those which aren't found and join-ed together with a comma.perl -F, -lpe '   $. == 1 and %h = /,([^=]*)=([^,]*)/g, next;   $l = $_;   $_ .= join ,, grep $l !~ /,\Q$_=/, keys %h;' your_2-line_fileResultXXXXXXX20170412,bu.1519=1,bu.1124=2,bu.1284=3,bu.1767=13,bu.1869=15,bu.1784=16,bu.1473=32,bu.1264=43,bu.1758=96,bu.1649=122,bu.1345=140,bu.1268=215,bu.1246=516,bu.1876=601,XXXXXXX20170413,bu.1123=1,bu.1767=27,bu.1784=32,bu.1473=57,bu.1869=41,bu.1264=91,bu.1284=54,bu.1758=191,bu.1268=387,bu.1345=319,bu.1649=322,bu.1246=1199,bu.1876=1383,bu.1519,bu.1124