这是我的文件:
$ cat sample1.txt
this is about weather.
this is summer.
I drink cold coffee
I eat Ice-cream
I wear cotton clothes.
this is winter
I drink hot coffee
I eat cake
I wear warm clothes.
this is summer.
I wear cotton sleeveless.
I drink juice.
现在在这个文件中,如果我发现一个单词";夏季";,我需要更新一个单词";棉花;至";"浅色";,具有sed或awk的任何输入plz。
cotton.sh内容:
#!/usr/bin/env bash
summer=$(grep -Fo -m1 summer $1)
if [[ ${summer} == "summer" ]]; then
sed -i 's/cotton/ligh color/g' $1
fi
执行:
/cotton.sh sample1.txt
备注:不要忘记为您的cotton.sh文件脚本(chmod u+x cotton.sh(设置执行权限