Have two files file1 and file2. Their contents are:
file1 - input
Line1
Line2
Line3
Line4
file2 - input
<head>
<intro> This is an introduction </intro>
<line> this is a line1 </line>
</head>
<head>
<intro> This is another intro </intro>
<line> this is a line2 </intro>
</head>
<head>
<intro> This is an introduction </intro>
<line> this is a line3 </line>
</head>
<head>
<intro> This is another intro </intro>
<line> this is a line4 </intro>
</head>
Want to read file1 and replace the line tag value in file2 with Line1, Line2, Line3, Line4 (see output). Which is the easiest method (sed, awk, grep, perl, python ...) of doing this?
Output
<head>
<intro> This is an introduction </intro>
<line> Line1 </line>
</head>
<head>
<intro> This is another intro </intro>
<line> Line2 </intro>
</head>
<head>
<intro> This is an introduction </intro>
<line> Line3 </line>
</head>
<head>
<intro> This is another intro </intro>
<line> Line4 </intro>
</head>
If you think this is a duplicate, please kindly link the duplicate. I have tried to go though solutions that look similar but none me found.
Edit: Just in case someone wants to append/concatenate instead of replacing, one can easily modify the markline expression in the python2 code of @cdarke as below and use.
markline = re.sub(r'</line>$',''+subt+'</line>',markline)