从文本文档中批量提取变化且未知的哈希码

鼻子

我想为server.jar文件编写一个小的更新工具,以节省我手动执行的所有工作,而我正在使用的程序会在创建新更新时创建一个包含文件的文件夹。该程序几乎是这样工作的:

get hash of current server.jar
find latest created folder (eg. update12)
open the file in the update12 folder (eg. update12.txt)
***extract the hash code -> %newHash%***    thats where im having the issue
compare the extracted hashcode (%newHash%) and the calculated hashcode (%currentHash%)
if they are not equal go to www.downloadupdate.com/updates/%newHash%/server.jar
download the file and replace the old server.jar with the new one.

我遇到的问题是我无法读出update12.txt中的哈希,该文件长约36000个符号,并且仅一行

“服务器”:{“ sha1”:“ 16f18c21286a3f566d3d0431d13aa133bebe6eff”

我想检测“服务器”:{“ sha1”:“部分并复制哈希值,之后我尝试了在该论坛上找到的许多选项,但似乎没有一个像这样工作

set /p txt=<update12.txt
pause >nul
echo %txt%
pause >nul
for /f %%i in ('powershell -noprofile -c "('%txt:"=\"%' -split '\""')[1]"') do set id=%%i
echo %id%

只是导致批处理文件立即关闭,另外设置/ p txt =

如果您有任何解决方案,我将不胜感激

鼻子
@echo off


Setlocal EnableDelayedExpansion
xcopy %appdata%\.minecraft\versions\%MCversion%\%MCversion%.json %appdata%\.minecraft\versions\%MCversion%\%MCversion%.text*
ren %appdata%\.minecraft\versions\%MCversion%\%MCversion%.text %MCversion%.txt

set search1= 
set search2=,
set search3=:
set textFile=%appdata%\.minecraft\versions\%MCversion%\%MCversion%.txt

:PowerShell
SET PSScript=%temp%\~tmpStrRplc.ps1
ECHO (Get-Content "%textFile%").replace("%search1%", "") ^| Set-Content "%textFile%">"%PSScript%"
Powershell -ExecutionPolicy Bypass -Command "& '%PSScript%'"
SET PSScript=%temp%\~tmpStrRplc.ps1
echo done.

ECHO (Get-Content "%textFile%").replace("%search2%", "") ^| Set-Content "%textFile%">"%PSScript%"
Powershell -ExecutionPolicy Bypass -Command "& '%PSScript%'"
SET PSScript=%temp%\~tmpStrRplc.ps1
echo done.

ECHO (Get-Content "%textFile%").replace("%search3%", "") ^| Set-Content "%textFile%">"%PSScript%"
Powershell -ExecutionPolicy Bypass -Command "& '%PSScript%'"
SET PSScript=%temp%\~tmpStrRplc.ps1
echo done.
:skip
ECHO (Get-Content "%textFile%").replace("server", "`r`nlookup") ^| Set-Content "%textFile%">"%PSScript%"
Powershell -ExecutionPolicy Bypass -Command "& '%PSScript%'"
echo done.

for /f %%a in ('findstr "lookup\"{\"sha1\"\"" %textFile%') do set "newVersion=%%a"
set newVersion=%newVersion:~15,40%
echo %newVersion%
del %textFile%
pause
:exit
exit

该代码对我有用,它的作用是:

copy the "update12.txt"
look for " " "," and ":" in the copied txt and delete the symbols
look for server replace it with a "*linebreak*lookup" 
find the string lookup"{"sha1""
trim the edges of the string with 15,40
done.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

通过文本文档中的文件列表批量处理文件

来自分类Dev

从文本文档中提取技术关键字

来自分类Dev

从文本文档中提取关键短语的规则

来自分类Dev

使用变量从python中的文本文档中读取

来自分类Dev

使用文本文档中的枚举快速搜索

来自分类Dev

在文本文档中查找特定行

来自分类Dev

文本文档中的C ++行索引

来自分类Dev

如何测试文本文档中编写的HTML代码?

来自分类Dev

在图像文本文档中随机生成合成噪声

来自分类Dev

使用文本文档更改列表中的项目

来自分类Dev

网络文本文档中的字数导致0

来自分类Dev

如何在文本文档中添加新行

来自分类Dev

Shell脚本从文本文档中调用行

来自分类Dev

删除文本文档中结尾相同的行

来自分类Dev

在Vim中从DOS到Linux的文本文档

来自分类Dev

在文本文档行中查找Sting

来自分类Dev

Vim中纯文本文档的项目符号列表

来自分类Dev

从文本文档中删除一行

来自分类Dev

使用文本文档中的枚举快速搜索

来自分类Dev

从文本文档中删除所有重复的行

来自分类Dev

从bash中的文本文档替换/更新列值

来自分类Dev

批量如何将文本文档转换为变量

来自分类Dev

C ++保存文本文档

来自分类Dev

使文本文档成为数字列表

来自分类Dev

Marklogic 如何检索文本文档

来自分类Dev

如何将文本文档中不断变化的(动态)字符串插入到.conkyrc中作为图像路径

来自分类Dev

如何从文本文档中提取信息然后打印出来

来自分类Dev

我需要将一个文本文档中的特定行数剪切并粘贴到另一个文本文档中

来自分类Dev

如何使用批处理命令将变量甚至文本传递到文本文档中?

Related 相关文章

热门标签

归档