我有一个文件,其中有许多这样写的行-
random text
some info,command -task shoot and more info
some info,command -new_task shoot and more info
more info and shoot a lot
command -task shoot and some more info and shoot a lot
我希望shoot
的首字母大写,command -* shoot
除外。
所以替换后,我的文件应如下所示-
random text
some info,command -new_task shoot and more info
more info and Shoot a lot
command -task shoot and some more info and Shoot a lot
我为此编写了以下脚本-
var="shoot";
sed -i "/-.*?${var}/ ! s/ ${var} / ${var^} /g" file;
除了command -* shoot
和shoot
写在同一行中的情况以外,此脚本可以正常工作。在这种情况下,我的输出为-
command -task Shoot and some more info and Shoot a lot
在这种情况下,shoot
都变成大写字母,这是不希望的。
有什么办法可以解决这个问题?