Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
580 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...