regexunixawkgreppcregrep

grep to find literal [square brackets] with specific data


My file contains the following lines:

hello_400 [200]
world_678 [201]
this [301]
is [302]
your [200]
friendly_103 [404]
utility [200]
grep [200]

I'm only looking for lines that ends with [200]. I did try escaping the square brackets with the following patterns:

and the results either contain all of the lines or nothing. It's very confusing.


Solution

  • I suggest to escape [ and ] and quote complete regex with single quotes to prevent your shell from interpreting the regex.

    grep '\[200\]$' file
    

    Output:

    hello_400 [200]
    your [200]
    utility [200]
    grep [200]