【Shell】sed xargs grep awk的組合用法

爱啦啦發表於2024-07-09

一、批次刪除指定字串"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}
     ' '_'

四、參考連結: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

相關文章