Comments on How to use grep to search for strings in files on the Linux shell

The grep command, which means global regular expression print, remains amongst the most versatile commands in a Linux terminal environment. It happens to be an immensely powerful program that lends users the ability to sort input based on complex rules, thus rendering it a fairly popular link across numerous command chains. The grep command is primarily used to search text or search any given file for lines containing a match to the supplied words/strings.

10 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: harshal sarode

hi sir,

i am facing a problm that how to fetch the common words from a file by grep.i tried thro the hardcoded string like

grep "abc" MyFile.txt.if i dont know if there are any common words in the file or not.then how i do it?plz help me so.

 

By: ramakrishna

Hi Sir,

I wants to get the content in beetween the particulers word like

It starts with subject and ends with subject and i wants the content in between that 

 

find . -exec grep -H "" {} \;

 

 

By: Stan Brow

Sounds like an awk task to me

By: dkolb001

I have two files with content. file1 has two columns of content, and file2 has a single column of content.

I would like to use grep to find all matching rows of file1 content, and that matches file2 row of content and display.

Not all content has a match for file1 and file2, but I would like the match to be correct. 

Any advise for this?

By: Daniel

I'm a linux novice and im using the grep function to search for the number 1. "grep 1 tdocs" now its working it's giving me car1 wheel1 but then also car11 and 12. How do i go about specifing the search so it's just car1 and wheel1? Many Thanks.

By: Brandon

I need some help with grep...

I have two .txt files that contain lists, the first, a.txt, contains:

abcd

and the other, b.txt, contains

abgcd

I want to use grep to output items from b.txt that arent in a.txt, in this case, "g"

I think it goes something like

grep -v --file=a.txt b.txt

By: Stan Brown

For what it is worth you may want to look into using the "strings" command for searching for strings in a binary, as it is explictly designed for that

 

By: Stan Brown

You need a better patern. to find a  "free standing" 1, you need to include what may precede and follow the 1. Tis is a little bit tricky, as some choies onclude a space, a tab, or a EOL

By: Tiago

Thanks! It helped me a lot!

By: Robert

Thank you! The recursive capabilities of the "grep" program helped me find the information I'd sought in no time.