在不同线路grep的文件多串(即整个文件,而不是基于行搜索)? [英] grep for multiple strings in file on different lines (ie. whole file, not line based search)?

查看:122
本文介绍了在不同线路grep的文件多串(即整个文件,而不是基于行搜索)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对grep包含单词丹麦语瑞典语挪威<文件/ code>上的任何线,可用收益code(因为我真的只喜欢有信息,该字符串包含,我的一行又进了一步,然后这一点)。

I want to grep for files containing the words Dansk, Svenska or Norsk on any line, with a usable returncode (as I really only like to have the info that the strings are contained, my one-liner goes a little further then this).

我在他们行很多这样的文件:

I have many files with lines in them like this:

Disc Title: unknown
Title: 01, Length: 01:33:37.000 Chapters: 33, Cells: 31, Audio streams: 04, Subpictures: 20
        Subtitle: 01, Language: ar - Arabic, Content: Undefined, Stream id: 0x20, 
        Subtitle: 02, Language: bg - Bulgarian, Content: Undefined, Stream id: 0x21, 
        Subtitle: 03, Language: cs - Czech, Content: Undefined, Stream id: 0x22, 
        Subtitle: 04, Language: da - Dansk, Content: Undefined, Stream id: 0x23, 
        Subtitle: 05, Language: de - Deutsch, Content: Undefined, Stream id: 0x24, 
(...)

下面是我想要的伪code:

Here is the pseudocode of what I want:

for all files in directory;
 if file contains "Dansk" AND "Norsk" AND "Svenska" then
 then echo the filename
end

什么是做到这一点的最好方法是什么?是否可以在同一行做了什么?

What is the best way to do this? Can it be done on one line?

推荐答案

您可以使用:

grep -l Dansk * | xargs grep -l Norsk | xargs grep -l Svenska

如果你想也隐藏文件找到:

If you want also to find in hidden files:

grep -l Dansk .* | xargs grep -l Norsk | xargs grep -l Svenska

这篇关于在不同线路grep的文件多串(即整个文件,而不是基于行搜索)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆