How to parse a file with special delimiters in a batch file?

笑着哭i 提交于 2019-12-20 06:18:42

问题


I want to parse a file that looks like this using batch :

a: string_containing_various_characters,.:and spaces/1
b: string_containing_various_characters,.:and spaces/2
c: string_containing_various_characters,.:and spaces/3
d: string_containing_various_characters,.:and spaces/4
e: string_containing_various_characters,.:and spaces/5
f: string_containing_various_characters,.:and spaces/6
g: string_containing_various_characters,.:and spaces/7

I need to extract every string following "a: ","b: ","c: " etc... I can't use space as a delimiter since there can be spaces in the strings. The only thing that is always true is that the first ": " will always be where I want to cut the line.

Any ideas?


回答1:


try this:

for /f "tokens=1*" %%a in (file) do for /f "delims=:" %%c in ("%%~b") do echo %%c


来源:https://stackoverflow.com/questions/18278001/how-to-parse-a-file-with-special-delimiters-in-a-batch-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!