How to extract text and set as variable Batch Code CMD

十年热恋 提交于 2019-12-12 03:29:18

问题


I would like to extract what users are online based on this text file:
https://minecraft-statistic.net/en/server/167.114.43.185_25565/json/

I will save it as a text file. Inside that there is something:

"players_list":["Raskhol"]["Lukaka"],"map":...etc

I would like to extract all the text between "_list": and ,"map" and set it as a variable. So that when I call the variable %Playerlist%, it would say:

["Raskhol"]["Lukaka"]

回答1:


similar to @geisterfurz007's answer, this one assumes the you are after the first instance of "players_list": before the first instance of ,"map"

@Echo Off
Set/P var=<some.json
Set var=%var:,"map"=&:%
Set var=%var:*"players_list":=%
Echo=%var%
Timeout -1



回答2:


Not tested due to beeing on phone.

@echo off
For /f "delims=: tokens=2" %%g in (PathTo\file.txt) do (
Set var=%%g
Goto:next
)
:next
Set var=%var:,map=%
echo %var%

Assumes players are the first to be listed.

Reads the file, takes the part after the first : up to the second one, stores it in var.
Then ,map gets replaces with nothing to result in just the players beeing echoed in the end.

Feel free to ask questions if something is unclear! Might take a while as I am currently mobile though.



来源:https://stackoverflow.com/questions/40999469/how-to-extract-text-and-set-as-variable-batch-code-cmd

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