BASH:replace text in files by sed

#!/bin/sh

TAG="aa:1234\/"
DST="aa\/"
for a in `find . -name '*.txt' -type f`
do
    c=`cat ${a} | grep ${TAG}`
    reg=".*${TAG}.*"
    if [[ "${c}" =~ $reg ]] ; then
        cat ${a} | sed "s/${TAG}/${DST}/g" 
    fi
done

 

 

posted @ 2020-04-06 17:40  xinyueliu  阅读(188)  评论(0)    收藏  举报