You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用批处理脚本按单词“code”拆分文本文件内容并实现指定换行效果

如何用批处理脚本按单词“code”拆分文本文件内容并实现指定换行效果

嘿,我完全get到你的需求啦——就是把原本挤在一行里的文本,拆成你想要的格式:版本号单独一行,每个"code":开头的内容也各占一行对吧?我给你整了个好用的批处理脚本,直接就能搞定:

@echo off
setlocal enabledelayedexpansion

:: 这里替换成你实际的输入、输出文件名
set "inputFile=source.txt"
set "outputFile=result.txt"

:: 第一步:把每个", "code": 替换成带换行的格式
(for /f "delims=" %%a in ('type "%inputFile%"') do (
    set "line=%%a"
    echo !line! | powershell -Command "$input = [Console]::ReadLine(); $input -replace ', \"code\":', ',`n`\"code\":\"'" > "%outputFile%"
))

:: 第二步:给版本号行后面加换行
powershell -Command "$content = Get-Content '%outputFile%' -Raw; $content -replace '(Version model [^,]+),', '$1,`n' | Set-Content '%outputFile%'"

echo 搞定啦!处理后的文件已经存到 %outputFile% 里啦
pause

简单使用指南:

  • 先把脚本里的source.txt替换成你实际要处理的文件名,result.txt改成你想要的输出文件名;
  • 脚本依赖Windows自带的PowerShell,不用额外安装任何工具;
  • 如果文件不在脚本同一文件夹,记得把文件名换成完整路径(比如D:\test\my_input.txt);
  • 双击运行脚本就行,处理完会弹出提示。

要是你运行的时候有啥问题,随时说哈!

备注:内容来源于stack exchange,提问作者James Thomas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 10:39:29