tags:

views:

46

answers:

3

Hi,

I want to search a word in lots of script files

It may linux software or script

Thanks

A: 

Next time, provide more info. with that said, you can try tools like grep, or awk with combination of find.

grep -r "word" *
ghostdog74
+2  A: 

Do:

man grep

And read that. Then checkout man sed and man awk and have a peek at Perl. It is essential to know these things on Unix-like systems!

Aiden Bell
A: 

Use a small shell script, which will print the number of occurrences of your search phrase in each file:

for file in `ls`; 
do 
    printf '%-50s' "$file"; 
    grep -c "SEARCH PHRASE HERE"
done

Which would give something like:

misc.rst                                          0
database_sources.rst                              0
postgis_cookbook.rst                              21
data_sources.rst                                  14
...

To find the occurrences of the phrase in each file, use cat and grep together:

cat -n filename | grep "SEARCH PHRASE HERE"

This would give you the lines in the file in which the phrase appears. The -n argument gives you the lines with numbers, for easy finding.

Adam Matan
grep -c "SEARCH PHRASE HERE" * is much shorter than all your above. also you do not properly handle multiple occurrences on one line.
Alex Brown
replaced to grep -c, thanks. Since the question was abound finding the words, not the number of occurrences, I think it would suffice - especially if using cat and grep afterwards.
Adam Matan