首页 > 解决方案 > 在 CMD 中添加空格以选择字符串时加入行不起作用

问题描述

我的测试字符串是:

this is a sentence.
google.com

here is another sentence.
microsoft.com
this sentence has no period

我的代码是:

@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.

我究竟做错了什么? 在此处输入图像描述

标签: stringbatch-filejoinreplacewhitespace

解决方案


鉴于您的示例文件内容更改和声明的意图,这可能足以满足您的需求,只需更改find.exefindstr.exe, (使用适当的选项)

@((For /F "EOL=|Delims=" %%# In ('^""%__AppDir__%findstr.exe" "\." "%UserProfile%\i.txt"^|"%__AppDir__%findstr.exe" "[^\.]$"^"')Do @Set /P "=%%# "<NUL)&Echo()>"%UserProfile%\o.txt"

推荐阅读