例如 逐行读取f1.txt,对于每一行L,将f2.txt替换为L的全部大写字符串。
f1.txt
sone
stwo
f2.txt
st
sone
stwo
so
所需输出:
st
SONE
STWO
so
我尝试过:
while IFS= read -r line; do
sed -e 's/\(.*\)/\U\1/' f2.txt
done < f1.txt
使用 bash >4.3:
# load strings into an array
mapfile -t a <f1.txt
# load file as a string (single array element)
mapfile -d '' b <f2.txt
# do substitutions
for s in "${a[@]}"; do b=${b//"$s"/"${s^^}"}; done
# output the result
printf '%s' "$b" >new_f2.txt