Есть два файла file1 и file2. Их содержание:
файл1 - ввод
Line1
Line2
Line3
Line4
файл2 - ввод
<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>
Хотите прочитать файл1 и заменить значение тега строки в файле2 на строку1, строку2, строку3, строку4 (см. вывод). Какой самый простой способ (sed, awk, grep, perl, python...) сделать это?
Выход
<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>
Если вы считаете, что это дубликат, пожалуйста, дайте ссылку на дубликат. Я пытался найти решения, которые выглядят похожими, но ни один из них не нашел.
Редактировать: На случай, если кто-то захочет добавить/объединить вместо замены, можно легко изменить выражение markline в коде python2 @cdarke, как показано ниже, и использовать.
markline = re.sub(r'</line>$',''+subt+'</line>',markline)
</intro>
опечаткой в некоторых строках с<line>
? - person Cyrus   schedule 16.05.2015