如何使用 findstr 将批处理结果写入文本文件

发布于 2024-08-16 05:06:20 字数 562 浏览 11 评论 0原文

我创建了一个批处理,它将使用 Windows FINDSTR 来搜索我的选择性输入。

我正在尝试将搜索词的结果记录在一个名为 results.txt 的文本文件中,

所以我确实有类似的内容,因此结果不会被覆盖:

>>Results.txt 

我创建了 txt 文件,因此它会写入其中,这是我尝试过但行不通:

findstr "\<%X%\>" *.txt  
echo >>results.txt

这就是我尝试记录搜索词结果的方法,但是没有任何反应。

当我有 findstr "<%X%>" *.txt >>results.txt

它尝试搜索 >>results.txt 但不合作。

有人知道该怎么办吗?

我这样做是因为 FINDSTR 将在 cmd 提示符下工作,但如果我得到太多结果,它会切断顶部,所以我希望它将所有结果写入 results.txt,这样我就可以查看整个结果而不进行任何剪切离开。

I created a batch that will use windows FINDSTR to search for my selective input.

I am trying to log my results of my search term in a text file called results.txt

So I do have something like this so results are kept not overwritten:

>>Results.txt 

I've created the txt file so it'll write to it, this is what I tried and won't work:

findstr "\<%X%\>" *.txt  
echo >>results.txt

That is what I have for trying to log my results of my search term, however nothing happens.

And when I have findstr "<%X%>" *.txt >>results.txt

It tries to search for >>results.txt and it's not cooperating.

Anyone know what to do?

I'm doing this because FINDSTR will work in the cmd prompt but if I get too many results it cuts off the top, so I want it to write all the results into the results.txt so I can view the whole results with nothing cut off.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

奢望 2024-08-23 05:06:20

尝试使用 /c:

findstr /c:"<%X%>" *.txt >> results.txt

编辑:不需要 ^ 在这里转义。

Try using /c:

findstr /c:"<%X%>" *.txt >> results.txt

Edit: didn't need the ^ escaping here.

花之痕靓丽 2024-08-23 05:06:20

您是否尝试过在>>之间加一个空格?和结果.txt
这里有一个示例

Have you tried putting a space in between >> and results.txt
There is an example of it here

路弥 2024-08-23 05:06:20

重定向子句的位置并不重要,所以我会尝试一下:

 >>results.txt findstr "\<%X%\>" *.txt

我还在 > 之前放置了一个 \ 因为我假设您需要开始和结束词标记而不是文字 >。如果我弄错了,就再把它拿出来。

但我不得不提的是,如果您想要做的只是阻止大量输出从控制台顶部滚动,您可以通过 more 传输整个内容:

type honkin_big_file | more

将充当寻呼机,这样你可以一点一点地查看。

The position of the redirection clause shouldn't matter, so I'd give this a shot:

 >>results.txt findstr "\<%X%\>" *.txt

I've also put a \ before the > because I'm assuming you want start and end word markers rather than a literal >. If I'm mistaken, just take it out again.

But I have to mention that, if all you want to do is stop the voluminous output from scrolling off the top of the console, you could just pipe the whole thing through more:

type honkin_big_file | more

will act as a pager so you can view it bit by bit.

拍不死你 2024-08-23 05:06:20

对于您的单行示例,您有这样的:

findstr "\<%X%>" *.txt >>results.txt

您的意思是这样吗:

findstr "\<%X%\>" *.txt >>results.txt

区别在于第一个示例中它正在搜索任何出现的“%X%>”在开始词边界上搜索“%X%”,第二个示例是在具有结束词边界的开始词边界上搜索“%X%”(例如单个词“%X%”)。

这对我有用。

For your single line example, you have this:

findstr "\<%X%>" *.txt >>results.txt

Did you mean this:

findstr "\<%X%\>" *.txt >>results.txt

The difference being in the first example it is searching for any occurrence of "%X%>" on a beginning word boundary and the second example is searching for "%X%" on a beginning word boundary with an end word boundary (e.g. single word " %X% ").

It works for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文