注意事项
- 查找以.proto为扩展名的文件:
find . -name "*.proto"
示例-1: 修改文件特定内容
#!/bin/bash
# Add 'syntax="proto2";' to the beginning of all proto files under
# PWD(recursively) if the proto file does not have it.
for file in $(find . -name "*.proto"); do
if grep -q 'syntax\s*=\s*"proto2";' $file; then
echo "[already had] $file";
else
sed -i '1s/^/syntax="proto2";\n/' $file
echo "[replaced] $file"
fi
done

本文介绍了一种使用bash脚本批量修改所有.proto文件的方法,确保每个文件开头都包含'syntax=proto2;'声明。通过find命令定位所有.proto文件,然后使用grep检查是否已存在该声明,若不存在则使用sed命令进行插入。
1990

被折叠的 条评论
为什么被折叠?



