File rewriting: One line is greater than variable's max size. Workaround?

前端 未结 3 1045
北恋
北恋 2021-01-24 08:11

I need to replace a single line in a file. Generally, this code works fine:

(The actual specifics on what this block is doing is not necessary for this question).

<
相关标签:
3条回答
  • 2021-01-24 08:41

    You could solve this with pure batch!

    :readLongLine
    < longline.tmp (
        for /L %%n in (1 1 20) do set /p part[%%n]=
    )
    

    After this your line is splitted into the variables part[1] .. part[20]

    Writing this to a new file you could use

    :writeLongLine
    <nul (
        for /L %%n in (1 1 19) do set /p ".=!part[%%n]!"
        (echo !part[20]!)
    ) > longLine2.tmp
    
    0 讨论(0)
  • 2021-01-24 08:56

    You could use some other scripting language like VBScript, JScript, or PowerShell.

    If you want to remain in the batch world, you can use a handy hybrid JScript/batch utility called REPL.BAT that performs regex search and replace on stdin and writes result to stdout. It is quite efficient, and works on any Windows machine from XP onward. It is pure script, so no exe download required. You can get REPL.BAT here. Full documentation is embedded within the script.

    0 讨论(0)
  • 2021-01-24 09:00

    Simply use sed, awk or Perl for the job.

    0 讨论(0)
提交回复
热议问题