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 at: 2015-06-22 10:55:54

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 at: 2015-07-17 12:10:44

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 at: 2017-04-04 18:28:33

Sounds like an awk task to me

By: dkolb001 at: 2016-06-23 15:46:33

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 at: 2016-07-08 07:33:08

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 at: 2016-12-04 16:53:46

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 at: 2017-04-04 18:26:51

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 at: 2017-04-04 18:30:50

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 at: 2019-10-30 12:04:39

Thanks! It helped me a lot!

By: Robert at: 2021-07-02 18:58:46

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