【Shell】sed xargs grep awk的组合用法
一、批量删除指定字符串"slave-xxx":
grep -inr "slave-xxx" | awk -F ':' '{print $1}' | xargs -n1 -I {} sed -i '/slave-xxx/d' {}
二、批量替换指定字符串"slave-xxx":
grep -inr "slave-abc" | awk -F ':' '{print $1}' | xargs -n1 -I {} sed -i 's/"slave-abc",/"slave-DFG",/g' {}
三、批量替换指定字符串"dailybuild_xxx_subtask":
find ./ -name "*.groovy" | xargs -r -0 -P1 -n1 bash -c '
src="${1}";
echo "=will update the project name for: $src=";
sed -i "s/dailybuild_xxx_subtask/db_x1_subtask/g" ${src}
' '_'
四、利用xrags批量执行变更仓库权限
ssh -p29418 gerrit.xxx.com gerrit ls-projects | grep "xxtools" | xargs -r -0 -P4 -n1 bash -c '
src="${1}";
echo "=will update the project permissions for: $src=";
ssh -p 29418 gerrit.xxx.com gerrit set-project-parent ${src} -p All-XXX
' '_'
五、利用shell数组批量变更仓库属性
projects_L=(
vendor/platform/boards
vendor/platform/chips
vendor/platform/framework
vendor/platform/apps
)
for project in ${projects_L[@]}
do
echo "=will update the project state for: $project=";
ssh -p 29418 gerrit.xxx.com gerrit set-project ${project} --project-state READ_ONLY
done
六、参考链接:sed & 快速修改、删除、增加、过滤文件内容
https://blog.csdn.net/m0_61066945/article/details/126082242
https://www.cnblogs.com/caoweixiong/p/10234053.html
https://www.runoob.com/linux/linux-comm-xargs.html