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
Teun Zengerink
  • 4,277
  • 5
  • 30
  • 32
Leo92
  • 724
  • 4
  • 16
  • 29

3 Answers3

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.

Bitwise
  • 7,577
  • 6
  • 33
  • 50
  • 1
    No problem, the dot is where to start recursing from and represents the current directory. – Bitwise Sep 07 '12 at 20:05
  • 1
    I have some questions: 1.can I use `or` for file type `(txt|css)` 2.How I can search for files names and types ? – Leo92 Sep 07 '12 at 20:27
0
find folder/ -name "*.css" |xargs grep "your-pattern"

You will need to install cygwin to do this.

Vijay Boyapati
  • 7,632
  • 7
  • 31
  • 48
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

lennon310
  • 12,503
  • 11
  • 43
  • 61