英文:
joining lines while adding white-spaces to select strings in CMD is not working
问题
翻译结果如下:
我的测试字符串是:
这是一个句子。
google.com
这是另一个句子。
microsoft.com
这个句子没有句号
我的代码是:
@echo off
setlocal EnableDelayedExpansion
set row=
@((For /F "EOL=|Delims=" %%# In ('"%AppDir%find.exe" "."^<"%UserProfile%\i.txt"')Do @Set /P "=%%# "<NUL)&Echo()>"%UserProfile%\o.txt"
echo %row% >%userprofile%\o.txt
echo %row%
C:\Users\qwerp>joint3
ECHO is off.
我期望得到的是:
google.com microsoft.com
但实际上我得到的是:
ECHO is off.
我做错了什么?
[1]: https://i.stack.imgur.com/38LXF.png
英文:
my test string is:
this is a sentence.
google.com
here is another sentence.
microsoft.com
this sentence has no period
my code is:
@echo off
setlocal EnableDelayedExpansion
set row=
@((For /F "EOL=|Delims=" %%# In ('^""%__AppDir__%find.exe" "."^<"%UserProfile%\i.txt"^"')Do @Set /P "=%%# "<NUL)&Echo()>"%UserProfile%\o.txt"
echo %row% >%userprofile%\o.txt
echo %row%
C:\Users\qwerp>joint3
ECHO is off.
i was expecting to get:
google.com microsoft.com
instead i got:
ECHO is off.
答案1
得分: 2
给定您的示例文件内容更改和所述意图,这可能足以满足您的需求,只需将 find.exe
更改为 findstr.exe
,(使用适当的选项):
@((For /F "EOL=|Delims=" %%# In ('"%__AppDir__%findstr.exe" "\." "%UserProfile%\i.txt"^|"%__AppDir__%findstr.exe" "[^\.]$"')Do @Set /P "=%%# "<NUL)&Echo()>"%UserProfile%\o.txt"
英文:
Given your example file content change and the stated intention, this may be sufficient for your needs, simply changing find.exe
to findstr.exe
, (with appropriate options):
<!-- language: lang-bat -->
@((For /F "EOL=|Delims=" %%# In ('^""%__AppDir__%findstr.exe" "\." "%UserProfile%\i.txt"^|"%__AppDir__%findstr.exe" "[^\.]$"^"')Do @Set /P "=%%# "<NUL)&Echo()>"%UserProfile%\o.txt"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论