在CMD中连接行并添加空格以选择字符串不起作用。

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

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.


我做错了什么?

在CMD中连接行并添加空格以选择字符串不起作用。


  [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 &quot;EOL=|Delims=&quot; %%# In (&#39;^&quot;&quot;%__AppDir__%find.exe&quot; &quot;.&quot;^&lt;&quot;%UserProfile%\i.txt&quot;^&quot;&#39;)Do @Set /P &quot;=%%# &quot;&lt;NUL)&amp;Echo()&gt;&quot;%UserProfile%\o.txt&quot;
echo %row% &gt;%userprofile%\o.txt
echo %row%
C:\Users\qwerp&gt;joint3
ECHO is off.

i was expecting to get:

google.com microsoft.com

instead i got:

ECHO is off.

what am i doing wrong?
在CMD中连接行并添加空格以选择字符串不起作用。

答案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 &quot;EOL=|Delims=&quot; %%# In (&#39;^&quot;&quot;%__AppDir__%findstr.exe&quot; &quot;\.&quot; &quot;%UserProfile%\i.txt&quot;^|&quot;%__AppDir__%findstr.exe&quot; &quot;[^\.]$&quot;^&quot;&#39;)Do @Set /P &quot;=%%# &quot;&lt;NUL)&amp;Echo()&gt;&quot;%UserProfile%\o.txt&quot;

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

发表评论

匿名网友

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

确定