批处理:从具有冒号和感叹号的文件中读取一行 [英] Batch: Reading in a line from a file that has a colon and exclamation
问题描述
我正在尝试从包含冒号和感叹号的文件中读取一行.当我回显那条线时,它仅显示结肠之后的所有内容.我需要保留enabledelayedexpansion以获取将在do循环中执行的更高级的代码.但是现在我只想正确地回声. 任何帮助将不胜感激!
I'm trying to read in a line from a file that contains a colon and exclamation point. When I echo that line, it only shows everything AFTER the colon. I need to keep the enabledelayedexpansion for more advanced code I will be doing in the do loop. But right now I just want to echo properly. Any help would be appreciated!
文件将显示以下内容:
! 12345 APX: 6.32
! 12345 APX: 6.32
我尝试的代码是:
setlocal EnableDelayedExpansion
cd C:\Users\jwagh\Desktop\
for /f "usebackq delims=" %%a in (test.txt) DO (
setlocal DisableDelayedExpansion
echo %%a
set line=%%a
set example=%line:~0,-1%
echo %example%
)
推荐答案
可能仅禁用延迟扩展是唯一可行的解决方案,但是根据您的数据,将delims
设置为!
会将%%a
设置为整行,减去开头的!
(显然仅假设一个已知长度的!
序列,并且总是在该行的前面)
Probably disabling delayedexpansion is the only practicable solution, but depending on your data, setting delims
to !
would set %%a
to the entire line, minus the initial !
(assuming obviously only one !
-sequence of known length and it always leads the line)
OR
for /f "usebackq delims=!" %%a in (%FamilyFile%) DO echo ^^!%%a
这篇关于批处理:从具有冒号和感叹号的文件中读取一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!