Replace a word in a file

后端 未结 4 1587
被撕碎了的回忆
被撕碎了的回忆 2021-01-23 04:36

I am new to Python programming...

I have a .txt file....... It looks like..

0,Salary,14000

0,Bonus,5000

0,gift,6000

I want to to replace

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-23 05:19

    I know that you're asking about Python, but forgive me for suggesting that perhaps a different tool is better for the job. :) It's a one-liner via sed:

    sed 's/^0,/1,/' yourtextfile.txt > output.txt
    

    This applies the regex /^0,/ (which matches any 0, that occurs at the beginning of a line) to each line and replaces the matched text with 1, instead. The output is directed into the file output.txt specified.

提交回复
热议问题