以下是带有脚本的示例file1和file2。不知道问题出在哪里。请帮忙。
File1
first line text xxxxx
second line xxxxx some more text
third line without to replace anything
line third xxxxx
文件2
first value
second value
some third value
脚本
#!/bin/sh
while read -r value1
do
while read -r value2
do
if [[ "$value1" != *"xxxxx"* ]]
then
echo $value1
continue
else
echo $value1 | sed "s/xxxxx/$value2/"
break
fi
done <file2
done <file1
预期产出:
first line text first value
second line second value some more text
third line without to replace anything
line third line third
但获得以下
first line text first value
second line first value some more text
third line without to replace anything
third line without to replace anything
third line without to replace anything
line third first value