17

I have a folder with sub-folders inside, all have many types of files. I want to search for a word inside the .css-files. I am using Windows 7 and I have grep.

How I can use grep to :

  1. Find pattern and print it
  2. Give file name (and path) if pattern found

3 Answers 3

32

Actually you don't need find. Just use:

grep -R --include=*.css -H pattern .

this will recurse and look for all *.css in subdirectories, while -H will show the filename.

Sign up to request clarification or add additional context in comments.

2 Comments

No problem, the dot is where to start recursing from and represents the current directory.
I have some questions: 1.can I use or for file type (txt|css) 2.How I can search for files names and types ?
0
find folder/ -name "*.css" |xargs grep "your-pattern"

You will need to install cygwin to do this.

Comments

0

if the files in which we have to look for, has pattern then we can use this. Consider I'm looking for pattern "cardlayout" in files named chap1.lst chap2.lst and so on. then the command

grep -e 'cardlayout' ` find . -name "chap??.lst"`

hope this would help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.