Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.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
Batch file 批处理文件,仅将findstr结果的第一个匹配项打印到文本文件_Batch File_If Statement_Cmd_Findstr - Fatal编程技术网

Batch file 批处理文件,仅将findstr结果的第一个匹配项打印到文本文件

Batch file 批处理文件,仅将findstr结果的第一个匹配项打印到文本文件,batch-file,if-statement,cmd,findstr,Batch File,If Statement,Cmd,Findstr,我正在尝试编写一个批处理文件,从fileA.txt读取列表,然后检查fileC.txt是否存在匹配项,如果不存在匹配项,则只将第一行匹配项从fileB.txt写入fileC.txt aaa1 some text aaaa some info aaaa4 some name bbb some name to ccc12 another name fileA.txt示例 aaa1 aaaa aaaa4 bbb ccc12 aaa1 some text aaa1 blah bla aaa1 .r

我正在尝试编写一个批处理文件,从fileA.txt读取列表,然后检查fileC.txt是否存在匹配项,如果不存在匹配项,则只将第一行匹配项从fileB.txt写入fileC.txt

aaa1 some text
aaaa some info
aaaa4 some name
bbb some name to
ccc12 another name
fileA.txt示例

aaa1
aaaa
aaaa4
bbb
ccc12
aaa1 some text
aaa1 blah bla
aaa1 .r
aaaa some info
aaaa blah bla
aaaa4 some name
bbb some name to
bbb more blah blah
ccc12 another name
ccc12 blah bla
fileB.txt示例

aaa1
aaaa
aaaa4
bbb
ccc12
aaa1 some text
aaa1 blah bla
aaa1 .r
aaaa some info
aaaa blah bla
aaaa4 some name
bbb some name to
bbb more blah blah
ccc12 another name
ccc12 blah bla
结果文件c.txt

aaa1 some text
aaaa some info
aaaa4 some name
bbb some name to
ccc12 another name
我想做什么

for /F %%i in (C:\filecopy\fileA.txt) do (
If exist (findstr /B /C:%%i fileC.txt) (
echo %%i exists ) else (
findstr /B /C:%%i fileB.txt >> fileC.txt )
)

但是,该代码不正确,我不确定如何最好地处理它。解决方法是在fileB.txt中搜索fileA.txt中的每个单词时,将findstr结果的第一个匹配项存储在fileC.txt中(正如您在问题标题中所指出的):