Replace a string in all files - Unix

后端 未结 2 1666
别那么骄傲
别那么骄傲 2021-02-04 17:23

I am trying to replace a string ::: with :: for all lines in a batch of txtfiles (it can be considered as a word since there\'s always a space in front

相关标签:
2条回答
  • 2021-02-04 17:53

    A simple loop to process each file with sed should suffice.

    for inp in ./td/*; do
        fname=${inp##*/}
        sed 's/:::/::/g' "$inp" > ./od/"$fname"
    done
    
    0 讨论(0)
  • 2021-02-04 18:14
    find . -name "./td/*.c" -exec sed -i "s/:::/::/g" '{}' \;
    

    No need for od/ at all.

    EDIT:

    A slightly simpler variation:

    ls td/*.c | xargs sed -i '' "s/:::/::/g"
    
    0 讨论(0)
提交回复
热议问题