How do I match more than one regular expression using grep?



  • The pipe character | means OR in regular expressions.

    Example text file used.

    $ cat textfile
    If the boots fit
    bootsy was here
    123456789
    

    We want to match any upppercase letter or anything with boots in the line. From out text file both regular expressions match, and hence only the numbers are excluded.

    $ grep -E "[A-Z]|boots" textfile
    If the boots fit
    bootsy was here
    

    86e323dc-c8c9-40ef-88b2-b551d0fd21be-image.png


Log in to reply
 

© Lightnetics 2024