Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I know grep -irn "#page-title" will search all files for matching text but for performance reasons I would like to limit the search ONLY to files that are css files. In powershell it is

ls *.css -r | select-string "#page-title"

Bonus points, how do I limit this to files that are NOT prefixed with "css_"

share|improve this question

2 Answers 2

up vote 5 down vote accepted
find -name "*.css" ! -name "css_*" | xargs grep -H "#page-title"

find is the unix command-line find, with 2 sets of parameters. The first parameter, -name "*.css", tells find to look for files with the CSS extension, the ! -name "css_*" parameter tells find to exclude or ignore files that start with css_. This list of files is then piped to the xargs command, which passes the list as parameters into the grep command, which is told to find "#page-title" from the list, and print the file name, using the -H parameter.

share|improve this answer
    
Could you provide some explanation about what your code does? –  Tom Wijsman Oct 31 '11 at 21:38
    
@TomWijsman added additional detail per your suggestion. –  Roy Rico Oct 31 '11 at 23:01

I've just uploaded grepcss: https://github.com/Red-Seadog/grepcss

grepcss understands CSS language, so you could do the find command as described above with

| xargs grepcss -s '#page-title'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.