Skip to content
Advertisement

grep multipe wildcards in string

Say I have a file that contains:

JavaScript

I want to grep and match lines that only contain ‘package’, ‘el6’, and ‘x86_64’

How would I go about doing that on a one liner using grep? The line must match all three and grep shouldn’t care about how many characters are in between. If there is a better tool for the job, I’m happy to use that instead.

I’ve tried the following and got no results:

JavaScript

Seeing posts and documentation, I understand that * does not mean the same thing as it would in shell. I’m looking for the equivalent of it to use in regex. Hope this makes sense.

Advertisement

Answer

Your attempt is very close. * in shell glob terms is roughly equivalent to .* in regex terms. . means “any character” and * is means “repeated any number of times (including zero).

Your regex just needs . before each *. The trailing * is not necessary:

JavaScript

Here is a sample run with your input:

JavaScript

Prints:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement