简体   繁体   中英

Grep multiple “and” expressions UNIX

I have been trying to find an answer for this question, but I have had difficulty getting a clear answer. Hopefully someone can assist.

I wanted to grep two patterns in a single or multiple files hoping the command will grep only files with both of the below patterns:

grep 35=[D|F|G] | 1=Account1 .log

I would like all 35=D,F,G messages that contain account 1 in .log

Hopefully someone can assist and thank you in advance.

Is the problem that you want to find files that contain two strings, but the strings won't be on the same line? If so, I just learned that today!

grep -l "first pattern" <files> | xargs grep -l "second pattern"

The first grep passes a list of file names to the second. xargs takes each of those filenames and passes them as an argument to the second grep.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM