find and replace string in a file

前端 未结 4 1944
天命终不由人
天命终不由人 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条回答
  •  萌比男神i
    2021-01-04 03:09

    The output goes to screen (stdout) because of the following:

    sed "s/$OLD/$NEW/g" "$f"
    

    Try redirecting to a file (the following redirects to a new files and then renames it to overwrite the original file):

    sed "s/$OLD/$NEW/g" "$f" > "$f.new" && mv "$f.new" "$f"
    

提交回复
热议问题