• I created a file (testimdb) with the following content:

    film: heat. year: 1995. director: michael mann. actors: al pacino, robert de niro, val kilmer
    film: the godfather part ii. year: 1974. director: francis coppola. actors: al pacino, robert de niro, diane keaton, robert duvall
    film: casino. year: 1995. director: martin scorsese. actors: robert de niro, sharon stone, joe pesci
    film: carlito's way. year: 1993. director: brian de palma. actors: al pacino, sean penn
  • I can grep for all movies starring both Pacino and De Niro (grep 'pacino\|de niro' /root/testimdb). this results in displaying all the films containing either of their names.

  • However, I want to exclude any film that does not star the both of them -- together in the same movie only. So, my grep search example above does not work for me as it correctly returns results that contain both stars in the same movies (heat, godfather 2) AND it also retrieves results of films of theirs not staring the other. For example, "Casino" stars De Niro, but not Pacino, and "Carlito's Way" only stars Pacino, but not De Niro.

  • How can I get the grep to display only results of Pacino and De Niro starring jointly in a film, ignoring all other results?

thanks, dave

1 Answer 1


This can be accomplished by piping grep to grep as follows (Although I'm sure there is a more efficient way):

grep 'de niro' testimdb | grep 'pacino'

Using extended regex in grep:

grep -E 'de niro.*pacino|pacino.*de niro' testimdb
  • hi Jesse_b, thank you that worked just fine! I'll refine it, but that's the answer i was looking for. this question/thread can now be closed. thank you so much!
    – code46
    Apr 14, 2018 at 18:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .