Findstr遇到特殊字符的处理

tz_being 2010-05-07 10:18:02
我有一个文件1.txt,内容如下:
引用
<fghfmogxe><; weoleer.exe> [(dsfified)sdffsher]
<bgswitch><Folder> []
<fgfdg><> [N/A]
<TsfaultCheck><; %fff%\ -k> [hfh mfging]
{ghh0C04 FolderF795683} <, >
[&使用hgf(fg)hgfh]
<\??\fghfhfh><N/A>
.fyt fh. ["%1" %*]

要求删除带Folder的那行,输出到2.txt中,原来带Folder的那行留空。我要达到那样的效果:
2.txt
引用
<fghfmogxe><; weoleer.exe> [(dsfified)sdffsher]

<fgfdg><> [N/A]
<TsfaultCheck><; %fff%\ -k> [hfh mfging]

[&使用hgf(fg)hgfh]
<\??\fghfhfh><N/A>
.fyt fh. ["%1" %*]

我的代码是:
for /f "tokens=*" %%i in (1.txt) do echo %%i|findstr /i /v /c:"Folder">nul && echo %%i>>2.txt||>>2.txt echo.
这行代码在普通文本中管用,但是1.txt中含有许多特殊字符就不管用了,求助。
...全文
574 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljc007 2010-05-08
  • 打赏
  • 举报
回复
test.bat

[code=BatchFile]@echo off
type nul >2.txt
for /f "delims=" %%a in (1.txt) do (
set "row=%%a"
setlocal enabledelayedexpansion
echo "!row!" | findstr /i /v /c:"Folder" >nul
if !errorlevel! neq 1 (
>>2.txt echo,!row!
) else (
>>2.txt echo,
)
endlocal
)
[/code]
ljc007 2010-05-08
  • 打赏
  • 举报
回复
GNU for Win32的sed.exe

sed "s/.*Folder.*//" 1.txt >2.txt
tz_being 2010-05-08
  • 打赏
  • 举报
回复
感谢两位,问题解决。我也找到一个方案,也贴上来吧:
引用
@echo off
(for /f "delims=" %%i in (1.txt) do (
set "str=%%i"
setlocal enabledelayedexpansion
if "!str:Folder=!" neq "%%i" (echo;)else echo %%i
endlocal
))>2.txt
pause
就是just4 2010-05-08
  • 打赏
  • 举报
回复
[code=BatchFile]@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in (1.txt) do (
set "test=%%i"
(echo "!test!"|findstr /i /v /c:"folder">nul)&&(echo !test!>>2.txt)||(echo.>>2.txt)
)
echo OK
pause>nul[/code]

6,850

社区成员

发帖
与我相关
我的任务
社区描述
Windows 2016/2012/2008/2003/2000/NT
社区管理员
  • Windows Server社区
  • qishine
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧