删除所有不包含句点的行 [英] Remove all lines which do not contain a period
问题描述
我在%userprofile%\i.txt
中有这样的文字:
PDF
wikkipedia.ord
notavalidURL
snapfish.com
.tunnelbear.com
mail.google.com/mail/u/0/#inbox
我想将其转换为这样的字符串:
I want to convert it to a string like this:
wikkipedia.ord snapfish.com .tunnelbear.com mail.google.com/mail/u/0/#inbox!
我只想使用本机cmd.exe语法执行此操作(不使用powershell,cygwin等).
I want to do this using native cmd.exe syntax only (no powershell, cygwin, etc.).
所以我知道我可以做到:
So I know that I can do this:
@echo off
setlocal EnableDelayedExpansion
set row=
for /f %%x in (%userprofile%\i.txt) do set "row=!row!%%x"
echo %row% >%userprofile%\o.txt
echo %row%
我的结果如何忽略不包含至少一个句点字符的所有子字符串?
How can my result ignore all substrings which do not contain at least one period character?
这将删除文件的内容:
@echo off
setlocal EnableDelayedExpansion
set row=
@For /F "EOL=|Tokens=*" %%x In ('^""%__AppDir__%find.exe" "."^<"%userprofile%\i.txt"^"') Do @Set "row=!row!%%x"
echo %row% >%userprofile%\o.txt
echo %row%
其中这将连接所有行,并且在子字符串之间不留空格:
where as this will join all lines leaving no whitespaces between the sub-strings:
@echo off
setlocal EnableDelayedExpansion
set row=
@For /F "EOL=|Tokens=*" %%x In ('^""%__AppDir__%find.exe" "."^<"%userprofile%\i.txt"^"') Do @Set "row=!row!%%x"
echo %row% >%userprofile%\o.txt
echo %row%
但是我需要在所有这些子字符串之间插入空格.
but i need white-spaces between all those substring being put out.
@echo off
setlocal EnableDelayedExpansion
set row=
@For /F "EOL=|Tokens=*" %%x In ('^""%__AppDir__%find.exe" "."^<"%userprofile%\i.txt"^"') Do @Set "row=!row! %%x"
echo %row% >%userprofile%\o.txt
echo %row%
这好多了,但是我在删除的字符串中留有空格.
this is a lot better but i have white-spaces left over from the strings that were removed.
我需要使用输出来分隔其余的字符串,但不要使文件带有随机的空白. 这样,我将能够将"作为StringSplit()或类似的参数传递.
i need the output to separate the remaining strings but not clutter the file with random white-spaces. this way i will be able to pass " " as a parameter for a StringSplit() or something like that.
这是代码中的'Tokens = '和取出的'Tokens = '之间的区别:
this is the difference between 'Tokens=' in the code and 'Tokens=' taken out:
推荐答案
我已经在注释中提供了足够的信息,可以帮助您纠正使用Find
命令完成的原始方法.
I've already provided in the comments sufficient information for you to correct your original methodology complete with the Find
command.
但是,鉴于您的示例文件内容和明确的意图,这可能足以满足您的需求:
However, given your example file content and stated intention, this may be sufficient for your needs:
@((For /F "EOL=|Delims=" %%# In ('^""%__AppDir__%find.exe" "."^<"%UserProfile%\i.txt"^"')Do @Set /P "=%%# "<NUL)&Echo()>"%UserProfile%\o.txt"
这篇关于删除所有不包含句点的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!