具有特定输入的多个 sed for 循环

时间:2021-02-18 16:32:26

标签: bash sed

我有一个 for 循环,里面有两个 sed 命令来编辑不同的文件。我的问题是第二个 sed 应该只编辑名为 aaa 的文件,但我收到错误 sed 无法编辑“不是常规文件”。

for file in $directory 
do [-e  "$file"] || continue
sed -i 's/hello/hello1/g' "$file"
sed -i 's/hallo/hello12/g' [[ "$file" ~ aaa ]]
done

1 个答案:

答案 0 :(得分:0)

建议更换

[-e  "$file"]

[ -e "$file" ]

sed -i 's/hallo/hello12/g' [[ "$file" ~ aaa ]]

[[ "$file" =~ ^aaa$ ]] && sed -i 's/hallo/hello12/g' "$file"