Linux find and replace

前端 未结 3 712
情深已故
情深已故 2021-02-01 07:59

How can I replace \"abc\" with \"abcd\" on all files of a folder using shell?

Is it possible using sed command?

相关标签:
3条回答
  • 2021-02-01 08:45

    Yes:

    find /the/folder -type f -exec sed -i 's,\<abc\>,&d,g' {} \;
    
    0 讨论(0)
  • 2021-02-01 08:46
    sed -i 's/abc/&d/g' *
    

    should work.

    0 讨论(0)
  • 2021-02-01 08:53

    Try the following command for the file file.txt:

    sed -i 's/abc/abcd/g' file.txt
    


    Try the following command for all files in the current folder:

    find . -maxdepth 1 -type f -exec sed -i 's/abc/abcd/g' {} \;
    

    For the files in the current directory and all subdirectories:

    find . -type f -exec sed -i 's/abc/abcd/g' {} \;
    

    Or if you are fan of xargs:

    find . -type f  | xargs -I {}  sed -i 's/abc/abcd/g' {}
    
    0 讨论(0)
提交回复
热议问题