Simple find and replace with sed

后端 未结 3 694
独厮守ぢ
独厮守ぢ 2020-12-10 04:46

I\'m trying to replace a number that is in a couple different strings in a text file. Basically it would take the form of

tableNameNUMBER
carNUMBER
         


        
3条回答
  •  暖寄归人
    2020-12-10 05:23

    to replace 1111 to 2222 you should probably try

    cat textfile.txt | sed -e 's/1111/2222/g'
    

    or

    cat textfile.txt | sed -e 's/1111/2222/g' > output.txt
    

    or

    NUMBER=1111 ; NEWNUMBER=2222; cat textfile.txt | sed -e "s/$NUMBER/$NEWNUMBER/g"
    

    There's no need to create separate script for such trivial task. Note "-e" switch for sed, "g" appended at the end of quoted command, and the difference between single and double quotes.

提交回复
热议问题