Search code examples
regexgrepdiffsdiff

How to grep for "<|>" ? (either the larger-than or small-than sign)


How can I grep for lines that contains either the larger-than sign or the smaller-than sign in them?

The following grep command returns nothing:

grep "<\|>" sdiff.out

Grepping, however, for just one of the signs at a time does return data from the file. The file contains output from the sdiff command.

The purpose of all this is to see only the actual lines that differ between two files.

Thank you for any tips.


Solution

  • Use -P or -E option in grep with >< symbols inside character class,

    grep -P '[><]' file
    

    OR

    grep -E '[><]' file
    

    Example:

    $ cat file
    chr -   xyz ordered_A01 5480    6144>
    chr -   xyz ordered_A01 5480    58001
    rm -rf ~/Desktop/-r <
    
    $ grep -P '[><]' file
    chr -   xyz ordered_A01 5480    6144>
    rm -rf ~/Desktop/-r <
    
    $ grep -E '[><]' file
    chr -   xyz ordered_A01 5480    6144>
    rm -rf ~/Desktop/-r <