【发布时间】:2021-01-28 22:01:18
【问题描述】:
我有一个脚本 test.sh
他有一些论点,例如:
./test.sh Forest Cuba World Hello
我做了一个 while read 循环,用在 shell 脚本中传递的参数 (Forest Cuba World Hello) 替换行的每个特定部分 (extractReplaceArgLine)。
while read line
do
extractReplaceArgLine=$(echo "${line}" | cut -d ' ' -f 1)
echo "${line}" | sed -e "s/"${extractReplaceArgLine}"/What I put Here ?/"
done < test.txt
考虑文件 test.txt :
Ocean is incredible
Spain is my favorite country
Moon calls me everyday
Goodbye World
所以,输出将是:
Forest is incredible
Cuba is my favorite country
World calls me everyday
Hello World
我该怎么做?
谢谢!
【问题讨论】: