RedGrittyBrick - указал - на ловушки надежного синтаксического анализа HTML.
Если, однако, ваш HTML отформатирован так же хорошо, как вы показываете, то это может сработать:
expr=
while read -r one two rest
do
expr="$expr; s/<uniquetag>$two<\/uniquetag>/<uniquetag>$two - $one<\/uniquetag>/"
done < file2
sed "$expr" sourcehtml > targethtml
... где вы могли бы, если вас устраивают результаты, изменить sed
выражение для:
sed -i "$expr" sourcehtml
... чтобы он редактировал файл sourcehtml на месте.
Есть много способов, которыми это может сломаться, некоторые из них:
Пример выполнения
Для первых трех строк "file2" и ...
sourcehtml:
<uniquetag>other</uniquetag>
<othertag>other</othertag>
<uniquetag>Mystring1</uniquetag>
<uniquetag>other</uniquetag>
<uniquetag>Mystring2</uniquetag>
<othertag>other</othertag>
<uniquetag>Mystring3</uniquetag>
<uniquetag>other</uniquetag>
<othertag>Mystring3</othertag>
Результат:
<uniquetag>other</uniquetag>
<othertag>other</othertag>
<uniquetag>Mystring1 - Info1</uniquetag>
<uniquetag>other</uniquetag>
<uniquetag>Mystring2 - Info2</uniquetag>
<othertag>other</othertag>
<uniquetag>Mystring3 - Info3</uniquetag>
<uniquetag>other</uniquetag>
<othertag>Mystring3</othertag>
Я бы сделал это с помощью Perl скрипта, как указано в следующем метакоде:
for each line in file2:
read line
parse line into 4 fields with a pattern match
build an associative array with $array{field2} = "field2 - field1"
slurp file1 into a single variable f
for each pattern match of /<UniqueTag>(match)</UniqueTag>/ in f:
replace "match" with $array{match}