英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论