想要从Windows命令脚本(CMD)文件中读取代码并提取信息。

huangapple go评论109阅读模式
英文:

Want to read Code from Windows Command Skipt(CMD) File and extract Information

问题

# 从代码的最后两行提取数据
xyz = "the command to get 340000021613012300"

如果需要更多帮助,请随时提问。

英文:

a specific directory receives some different files including some .cmd files.

Here is and example of one of these:

X_COMMAND=DELETE_DOCUMENT
X_DOCIDENTIFICATION=FREE
DTY=MSDS
X_DELIMITER=;
X_FollowingFields=STA;DTY;PRN;SID;CTY;LAN;VKG
V;MSDS;340000021613012300;800000000160;ES;E;ES00

I want to work with the last 2 lines of Code to extract Data:

String xyz = (the command to get 340000021613012300);

The Question is: How do I get this Data?

I have tried to look this up, but did not find anything regarding this issue. If you can help me with this or redirect me to the information I look for I would appreciate that.

Thank you for your time helping me here.

答案1

得分: 1

这是一种实现方法。如果您在支持的Windows系统上,PowerShell将会可用。

FOR /F %%A IN ('powershell -NoLogo -NoProfile -Command ^
    "(Get-Content -Path \"C:\src\t\Get-LastLineData.txt\" |^
        \"Select-Object -Last 1).Split(';')[2]"') DO (
    SET "xyz=%%~A"
)
ECHO %xyz%

如果您的脚本可以用PowerShell编写,那么只需要这样:

$xyz = (Get-Content -Path "C:\src\t\Get-LastLineData.txt" |
    Select-Object -Last 1).Split(';')[2]
英文:

Here is one way to do it. If you are on a supported Windows system, PowerShell will be available.

FOR /F %%A IN ('powershell -NoLogo -NoProfile -Command ^
    "(Get-Content -Path "C:\src\t\Get-LastLineData.txt" |" ^
        "Select-Object -Last 1).Split(';')[2]"') DO (
    SET "xyz=%%~A"
)
ECHO %xyz%

If your script could be written in PowerShell, it would just be:

$xyz = (Get-Content -Path "C:\src\t\Get-LastLineData.txt" |
    Select-Object -Last 1).Split(';')[2]

答案2

得分: 1

使用`cmd`命令:

    for /f "tokens=3 delims=;" %%a in (file.ext) do set "xyz=%%a"
    echo %xyz%

(假设您想要获取最后一行的第三个标记)
英文:

Using just cmd:

for /f "tokens=3 delims=;" %%a in (file.ext) do set "xyz=%%a"
echo %xyz%

(assuming you want the third token of the last line)

huangapple
  • 本文由 发表于 2020年9月18日 18:26:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/63953959.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定