-1

I have a file called a.txt

something [low] https://url/low.txt
something [info] http://url1/low.txt
something [low] https://url2/robots.txt

How can i achieve this output using grep command?

something [low] https://url/low.txt
something [low] https://url2/robots.txt

thanks in advance

1 Answers1

0
grep 'something \[low\]' a.txt

The single quotes are to prevent the shell from interpreting the brackets (and breaking on the space). grep itself uses brackets for simple regular expressions, so the brackets need to be escaped separately, inside the single quotes, to not have grep interpret them as special.

Using grep -F or fgrep doesn't use regular expressions: everything to grep on is taken as a single string pattern. The single quotes would still be necessary to prevent the shell from interpreting the brackets specially.

9769953
  • 10,344
  • 3
  • 26
  • 37