cat 文件或标签和 xargs grep 文件中的标签

发布于 2024-10-21 07:00:48 字数 362 浏览 2 评论 0原文

我认为这只是一个简单的命令,但我根本无法找到解决方案

我想使用标签(由多行分隔)

File1

来捕获一个文件

aaa
bbb
ded

,然后将这些标签(逐行)grep 到一个文件中,我们称之为 TargetFile

我所做的如下:

cat File1 | xagrs grep {} TargetFile

它不会对 TargetFile 执行 grep 操作。我该怎么做呢?

我目前正在使用 mobaxterm

I think it is a simple command only but i simply could not come to a solution

I would like to cat a file with tags (separated by many lines)

File1

aaa
bbb
ded

and then grep those TAGS(line by line) to a single file, lets call it TargetFile

What I have done is the following:

cat File1 | xagrs grep {} TargetFile

It does not do a grep on TargetFile. How can I do it?

I am using mobaxterm at the moment

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

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

发布评论

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

评论(7

风向决定发型 2024-10-28 07:00:48
fgrep -f File1 TargetFile

另请注意,没有使用 Cat 的无用用途。

fgrep -f File1 TargetFile

Note also the absence of a Useless Use of Cat.

时光匆匆的小流年 2024-10-28 07:00:48

像往常一样,不止一种方法可以做到这一点:

xargs -n 1 grep Targetfile -e < File

as usual more than one way to do it:

xargs -n 1 grep Targetfile -e < File
怪我闹别瞎闹 2024-10-28 07:00:48
cat File1 | xargs -I {} grep {} TargetFile
cat File1 | xargs -I {} grep {} TargetFile
骷髅 2024-10-28 07:00:48

根据文件的大小,这将运行得更快:

cat File1 | parallel -j0 grep {} TargetFile

如果 File1 中的标签数量小于可以并行运行的进程数量,则 TargetFile 将仅从磁盘读取一次。如果 TargetFile 大于磁盘缓存,这可能是个好主意。

要了解有关 GNU Parallel 的更多信息,请观看介绍视频:http://www.youtube.com/watch? v=OpaiGYxkSuQ

Depending on the size of the files this will run faster:

cat File1 | parallel -j0 grep {} TargetFile

If the number of tags in File1 is smaller than the number of processes you can run in parallel, then TargetFile will only be read once from disk. If TargetFile is bigger than your disk cache the this is probably a good idea.

To learn more about GNU Parallel see the intro video: http://www.youtube.com/watch?v=OpaiGYxkSuQ

我们的影子 2024-10-28 07:00:48

好吧,我想我在其他论坛搜索后找到了答案

> for i in `cat File1` ; do grep $i TargetFile; done

well I think i found the answer after searching in other forums

> for i in `cat File1` ; do grep $i TargetFile; done
你在我安 2024-10-28 07:00:48
cat File1 | while read tag; do grep $tag TargetFile; done
cat File1 | while read tag; do grep $tag TargetFile; done
唱一曲作罢 2024-10-28 07:00:48
cat File1 | xagrs -i grep {} TargetFile
cat File1 | xagrs -i grep {} TargetFile
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文