我有类似于以下示例的 .txt 文件(1000 个)。我必须在 Dos.bat 文件中执行此操作,没有选项(它将被其他 .bat 文件调用)(运行 Windows 7,没有安装或下载任何其他文件或程序的选项)。这些文件的大小通常为 30k。我需要用回车替换 $ 的字符。每个文件中将有多达 2-300 个 $ 字符,因此我无法解析 $ (除非我遗漏了什么)。
看起来很简单,但我一直在努力搜索试图做到这一点。我在某处找到了一个示例,但它似乎限制为最大 8k。文件。(见问题结尾)
文件中逗号和单词的模式随每个文件而变化。唯一不变的是 $ 应该有一个新行的地方。例子:
原始文件:
ENTRY,1,423-6823,"FILTER ASSEMBLY, DAVCO",A,,1,2,,,,,,@FIELD,SUGG_QTY,1$ENTRY,2,423-6939,"FILTER, FUEL - SPIN-ON",A,,2,3,,,,,,@FIELD,SUGG_QTY,1$ENTRY,3,423-3143,"MOUNT PLATE, FILTER ASSEMBLY",1,,1,4,,,,,,$ENTRY,4,698-9393,"HOSE ASSEMBLY, #16 X 112""",1,,1,5,,,,,,$ENTRY,5,418-6146,"HOSE ASSEMBLY, #16 X 118""",1,,1,6,,,,,,$ENTRY,6,408-2841,"HOSE ASSEMBLY, #16 X 40""",1,,1,7,,,,,,$ENTRY,7,412-7996,"HOSE ASSEMBLY, #12 X 40""",1,,1,8,,,,,,$ENTRY,8,400-2483,"ELBOW, #16 FJ X 90 deg. X #16 MJ - SWIVEL",3,,1,9,,,,,,$ENTRY,9,N.P.N.,FILTER MOUNT [FURNISHED WITH ENGINE],A,,1,10,,,,,,$ENTRY,10,423-6822,"FILTER, FUEL",A,,1,11,,,,,,@FIELD,SUGG_QTY,2$ENTRY,11,400-2481,"ELBOW, #12 FJ X 90 deg. X #12 MJ - SWIVEL",1,,1,12,,,,,,
依此类推,大小可能为 30-40k。
当 $'S 被删除并替换为 txt 文件中的回车时,该文件应如下所示:
ENTRY,1,423-6823,"FILTER ASSEMBLY, DAVCO",A,,1,2,,,,,,@FIELD,SUGG_QTY,1
ENTRY,2,423-6939,"FILTER, FUEL - SPIN-ON",A,,2,3,,,,,,@FIELD,SUGG_QTY,1
ENTRY,3,423-3143,"MOUNT PLATE, FILTER ASSEMBLY",1,,1,4,,,,,,
ENTRY,4,698-9393,"HOSE ASSEMBLY, #16 X 112""",1,,1,5,,,,,,
ENTRY,5,418-6146,"HOSE ASSEMBLY, #16 X 118""",1,,1,6,,,,,,
ENTRY,6,408-2841,"HOSE ASSEMBLY, #16 X 40""",1,,1,7,,,,,,
ENTRY,7,412-7996,"HOSE ASSEMBLY, #12 X 40""",1,,1,8,,,,,,
ENTRY,8,400-2483,"ELBOW, #16 FJ X 90 deg. X #16 MJ - SWIVEL",3,,1,9,,,,,,
ENTRY,9,N.P.N.,FILTER MOUNT [FURNISHED WITH ENGINE],A,,1,10,,,,,,
ENTRY,10,423-6822,"FILTER, FUEL",A,,1,11,,,,,,@FIELD,SUGG_QTY,2
ENTRY,11,400-2481,"ELBOW, #12 FJ X 90 deg. X #12 MJ - SWIVEL",1,,1,12,,,,,,
我可以使用以下代码对小文件执行此操作(在某些站点上找到)。它工作得很好,但是当文件大小达到大约 9k 时它会失败并且只返回第一行。
For /f "tokens=1,* delims=$" %%a in (testfile.txt) Do (
Echo.%%a>>out.txt
If not "%%b"=="" Call :change %%b)
GoTo :EOF
:change
For /f "tokens=1,* delims=$" %%a in ("%*") Do (
Echo.%%a>>out.txt
If not "%%b"=="" Call :change %%b)
GoTo :EOF
任何帮助是极大的赞赏。