237

I have a file file1 which ends with Success... OR success...

I want to grep for the word success in a way which is not case sensitive way.

I have written the following command but it is case sensitive

cat file1 | grep "success\.\.\."

How can i change it so that it returns 0 with both Success... OR success...

vvvvv
  • 25,404
  • 19
  • 49
  • 81
all_techie
  • 2,761
  • 2
  • 11
  • 19

3 Answers3

404

You can use the -i flag which makes your pattern case insensitive:

grep -iF "success..." file1

Also, there is no need for cat. grep takes a file with the syntax grep <pattern> <file>. I also used the -F flag to search for a fixed string to avoid escaping the ellipsis.

Imran
  • 12,950
  • 8
  • 64
  • 79
  • 11
    doesn't simple `grep -i success file1` returns the same output as expected here? – User123 Jan 29 '18 at 09:33
  • 17
    @User123 Yes, but `-F` searches for the exact string, without doing any regex parsing, so it's often faster and easier to type if you (as the OP did) have special characters in the phrase you're looking for – Nic Jul 23 '18 at 20:49
  • why did you use `F`? – alper Jan 31 '23 at 13:48
3

Since this bubbled up due to an edit being made, I'll add another method just for the fun of it.

grep '[Ss]uccess' file.txt

This uses the regular expression syntax for a character class of capital or lower 's'.

Gary_W
  • 9,933
  • 1
  • 22
  • 40
2

For me SQL=echo $line | grep -iF "SQL"; IT works perfect

Daljit Sinz
  • 121
  • 8