Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
589 views
in Technique[技术] by (71.8m points)

to extract lines appearing inbetween { } in text file through batch file

How can we extract lines appearing between { } in text file through batch file.

Text file would be in format:

Name : ABC
Place : xyz
Data :dd/mm/yyyy

{"return":"good","message":"ABC is present in xyz place","SSN":"-----------------345679HISKWBXMVTXVEULWXVC
VBXSWGVXBWSDCXLWUDV"}

I tried using the below code snippet, However it lists all the contents of text file . How can we extract the contents within {}

for /f "tokens=*" %%x in (filename) do set extract=!extract!%%x

question from:https://stackoverflow.com/questions/66061821/to-extract-lines-appearing-inbetween-in-text-file-through-batch-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This might help you:

@echo off
for /f "usebackq tokens=1 delims={}" %%a in ("Whateverfile.txt") do set "data=%%a"
echo %data%

type for/? in cmd for more info or For-loop


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...