How to grep for case insensitive string in a file?
145,217
Solution 1
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.
Solution 2
For me SQL=echo $line | grep -iF "SQL"
;
IT works perfect
Related videos on Youtube
Author by
all_techie
Updated on July 22, 2022Comments
-
all_techie almost 2 years
I have a file
file1
which ends withSuccess...
ORsuccess...
I want to
grep
for the wordsuccess
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 bothSuccess...
ORsuccess...
-
User123 over 6 yearsdoesn't simple
grep -i success file1
returns the same output as expected here? -
Nic almost 6 years@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 -
ashleedawg almost 5 yearscould you explain what this is doing?
-
CindyH almost 4 yearsLovely answer to a newbie - don't say "yuck you're doing it wrong", say "here's the answer to your question and a bonus improvement". Well done!