Linux command to replace string in LARGE file with another string

前端 未结 7 792
终归单人心
终归单人心 2021-01-02 13:33

I have a huge SQL file that gets executed on the server. The dump is from my machine and in it there are a few settings relating to my machine. So basically, I want every oc

7条回答
  •  甜味超标
    2021-01-02 14:09

    Try sed? Something like:

    sed 's/c:\/\/temp/\/\/home\/\/some\/\/blah/' mydump.sql > fixeddump.sql
    

    Escaping all those slashes makes this look horrible though, here's a simpler example which changes foo to bar.

    sed 's/foo/bar/' mydump.sql > fixeddump.sql
    

    As others have noted, you can choose your own delimiter, which would prevent the leaning toothpick syndrome in this case:

    sed 's|c://temp\\|home//some//blah|' mydump.sql > fixeddump.sql
    

    The clever thing about sed is that it operating on a stream rather than a file all at once, so you can process huge files using only a modest amount of memory.

提交回复
热议问题