Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查找&;仅使用Windows批处理复制文件中的字符串_Windows_Command Line_Batch File - Fatal编程技术网

查找&;仅使用Windows批处理复制文件中的字符串

查找&;仅使用Windows批处理复制文件中的字符串,windows,command-line,batch-file,Windows,Command Line,Batch File,我在input.txt中调用要搜索的文件和要查找mystring的字符串 input.txt的示例内容 for/F“delims=“%%a in('findstr“mystring”input.txt')。这个搜索“mystring”,对吗?。但“mystring”是未知的,无法搜索。它被和包围着。也许我的描述有误导性?行动!我的错误,我有点心不在焉。。。只需在findstr命令中通过“”更改“mystring”;我已经在上面的程序中进行了测试:输出是相同的;-)它的大小写敏感=D非常感谢(原件

我在input.txt中调用要搜索的文件和要查找mystring的字符串

input.txt的示例内容


for/F“delims=“%%a in('findstr“mystring”input.txt')
。这个搜索“mystring”,对吗?。但“mystring”是未知的,无法搜索。它被和包围着。也许我的描述有误导性?行动!我的错误,我有点心不在焉。。。只需在findstr命令中通过“”更改“mystring”;我已经在上面的程序中进行了测试:输出是相同的;-)它的大小写敏感=D非常感谢(原件>原件)我怀疑没有愚蠢的把戏让FINDSTR在变量内搜索字符串而不是在文件内搜索?@nixda:只需将变量值作为筛选器传递给FINDSTR:
echo%variable%|FINDSTR…
,但在这种情况下,结果可能是相同的值,也可能是零,这取决于搜索字符串是否在变量内部……“FOR循环和SET命令语法对我来说太笨拙了”——遗憾的是,Windows批处理脚本的许多功能可能会显得笨拙。有些脚本即使在您习惯了它们之后,仍然看起来很笨拙,特别是如果您知道其他脚本工具或语言中的解决方案可能更简单/更清晰的话。然而,对于您来说,for/F循环和SET/P分配可能是Windows批处理脚本中逐行处理文本文件的两个最基本的本机设备。意思是你最好习惯它们。:)而且,谁知道,它们最终可能会对你产生影响。:)
randomstring1<>"\/=:
randomstring2<ORIGINAL>mystring</ORIGINAL>randomstring3
@echo off
set "x=randomstring1<>"\/=:randomstring2<ORIGINAL>mystring</ORIGINAL>randomstring3"
set "x=%x:*<ORIGINAL>=%"
set "x=%x:</ORIGINAL>*=%"
set  x=%x:~2%
echo %x%
pause
@echo off
rem Let findstr to find the LINE you want (only once):
for /F "delims=" %%a in ('findstr "<ORIGINAL>" input.txt') do set "line=%%a"
ECHO LINE: "%line%"
rem Change left delimiter by {
set "line=%line:<ORIGINAL>={%"
rem Change right delimiter by }
set "line=%line:</ORIGINAL>=}%"
ECHO STRING DELIMITED: "%LINE%"
rem Get second token delimited by { and }
for /F "tokens=2 delims={}" %%a in ("%line%") do set string=%%a
ECHO STRING: "%STRING%"
rem Copy string to clipboard
REM echo %string%| clip
LINE: "randomstring2<ORIGINAL>mystring</ORIGINAL>randomstring3"
STRING DELIMITED: "randomstring2{mystring}randomstring3"
STRING: "mystring"
set "line=%line:*<ORIGINAL>=%"
for /F "delims=}" %%a in ("%line%") do set string=%%a