find and replace string in a file

前端 未结 4 1940
天命终不由人
天命终不由人 2021-01-04 02:25

I\'m trying to find and replace a string in a folder of files.

Could someone possibly help me?

My script is as follows:

#!/bin/bash
OLD=\"Thi         


        
4条回答
  •  粉色の甜心
    2021-01-04 02:54

    Check this out

    http://cs.boisestate.edu/~amit/teaching/handouts/cs-unix/node130.html

    ##########################################################
    \#!/bin/sh
    
    \# sed/changeword
    
    prog=`basename $0`
    
    case $# in
    0|1) echo 'Usage:' $prog ' '; exit 1;;
    esac
    
    old=$1
    new=$2
    for f in *
    do
            if test "$f" != "$prog"
    
            then
                if test -f "$f"
                then
                    sed "s/$old/$new/g" $f > $f.new
                    mv $f $f.orig
                    mv $f.new $f
                    echo $f done
                fi
            fi
    done
    
    ##############################################################
    

提交回复
热议问题