Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In Linux, How do I display lines that contain a string in a text file, such as:

search "my string"  file_name

How do I make the search case sensitive/insensitive? And how do I also display the line numbers?

Regards

share|improve this question

1 Answer 1

up vote 4 down vote accepted

well

grep -n "my string" file_name 

will do for your particular query. GREP is by default case sensitive in nature and to make it case insensitive you can add -i option to it. The -n option displays the line numbers. For other myriad options, I recommend

man grep

for more interesting pattern matching capability of GREP.

share|improve this answer
    
Thanks. How do I also get the line numbers? –  alwbtc Jul 22 '12 at 15:07
    
-n will get you the line number –  kaji Jul 22 '12 at 15:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.