batch-file - 如何从批处理输出文件中删除额外的文本和空格
问题描述
我正在尝试从工作中的多个设备收集 ICCID。
我能够收集和输出 ICCID,但无法删除 device.txt 内容左侧的所有字符,只留下 15 位数字。
到目前为止,我能够创建一个批处理文件来收集 ICCID 并输出到 device.txt 文件。
@echo off
(
%windir%\sysnative\cmd.exe /c netsh.exe mbn show interfaces | find "Device Id"
) > C:\Users\Test\Pictures\device.txt
这是输出文件中显示的内容:
Device Id: 990001234567890
我需要它只输出 device.txt 文件中的数字:
990001234567890
解决方案
您应该能够netsh.exe
直接执行 - 不需要cmd.exe /c
.
用于FOR /F
解析命令的输出,如下所示:
for /f "delims=: tokens=2" %%A in (
'netsh.exe mbn show interfaces ^| find "Device Id"'
) do >"C:\Users\Test\Pictures\device.txt" echo %%A
delims=:
指定在每个:
. tokens=2
指定获取第二个令牌。
输出将有前导空格。为了消除空格,加入一个额外简单的 FOR 循环:
for /f "delims=: tokens=2" %%A in (
'netsh.exe mbn show interfaces ^| find "Device Id"'
) do for %%B in (%%A) do >"C:\Users\Test\Pictures\device.txt" echo %%B
推荐阅读
- java - 如何在 VS 代码的调试控制台中而不是在我的终端上打印日志消息?
- nlp - 使用 pytorch 闪电对 BERT 模型进行多标签文本分类会导致 DataLoader 中出现 KeyError
- amazon-web-services - 为什么一个 group by 的聚合这么慢?
- android-studio - 短信管理员 getSmsManagerForSubscriptionId
- css - 文字描边线css
- julia - 为什么当我调用两次并且编译次数占用率低时性能不同?
- swift - 如何使 NavigationLink 以另一个视图中的布尔集为条件?
- javascript - react中如何分离功能组件的逻辑?
- bash - Bash脚本:获取输入参数的数量,不包括选项
- python - 在屏蔽语言建模期间屏蔽每个输入句子中的特定标记