PowerShell multiple string replacement efficiency

前端 未结 4 920
梦谈多话
梦谈多话 2020-12-20 16:54

I\'m trying to replace 600 different strings in a very large text file 30Mb+. I\'m current building a script that does this; following this Question:

Script:

4条回答
  •  感动是毒
    2020-12-20 17:28

    I also have no idea how to solve this in powershell, but I do know how to solve it in Bash and that is by using a tool called sed. Luckily, there is also Sed for Windows. If all you want to do is replace "something#" with "somethingelse#" everywhere then this command will do the trick for you

    sed -i "s/something([0-9]+)/somethingelse\1/g" c:\log.txt
    

    In Bash you'd actually need to escape a couple of those characters with backslashes, but I'm not sure you need to in windows. If the first command complains you can try

    sed -i "s/something\([0-9]\+\)/somethingelse\1/g" c:\log.txt
    

提交回复
热议问题