[SOLVED] How can I use grep in specific files?

Status
Not open for further replies.

u24c02

Advanced Member level 1
Joined
May 8, 2012
Messages
404
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Visit site
Activity points
4,101
Hi

When I used grep to search some text, I usually used like this.

grep -r -n "xxx" *

But it is not efficiently. I want to find in bunch of especially some files.

So does anyone know how to use?
 

Say I want to search for "Blah" in files with a txt extension. I'd do something like this:

Code:
IFS=$(echo -en "\n\b")
for x in $(find . -name "*.txt")
do
  grep "Blah" "$x"
done

You can also concatenate it in one line by replacing carriage returns by ;
 

can you give an example what exactly you want to do with grep ?

there is egrep command , may be you can take a look on that.
 

grep "<searching_keyword>" <file or folder> > <output to a result file>.
Example:
grep "my_name" namelist.txt > my_name_found.txt

You can add -i or -r option to ignore case or search the whole subfolders respectively.
You can use pipe cmd "|" to refine your search result as well.
 

in "grep -r -n "xxx" *", replaced the "*" with the groupe of files you want to cover.
could you give an example of the "bunch of especially some files"?
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…