Grep in CSH

March 21, 2009 at 22:32:12
Specs: Windows XP
Hi, im trying to create a script that will count a number of files in the given directory, that contain the specified word. I am getting the Command not found (script does have the x permission) Any idea? It's the cshell
THanks !

#!/bin/usr/csh
# Write a script that will count number of files including the word specified by user

grep -l $1 pwd


See More: Grep in CSH

Report •


#1
March 22, 2009 at 11:19:32

#!/usr/bin/csh

set mycnt=`grep -l $1 * | wc -l`
echo $mycnt


Report •

#2
March 25, 2009 at 00:00:27
Thanks so much ! That does work except it lists the name of the files containing the searched for word. I am trying to get the number of the files containing the selected word, as in:

Total number of files containing $1 (selected word) is: 5

Thanks agian
Morava


Report •

#3
March 25, 2009 at 08:50:25
Are you certain that you are using the correct option to grep:

#!/usr/bin/csh

set mycnt=`grep -l $1 * | wc -l`
echo "Total number of files containing '$1' (selected word) is: $mycnt"

I'm not having any trouble. If I search for the word: while in my particlar case I get this output:

Total number of files containing 'while' (selected word) is: 7


Report •

Related Solutions

#4
March 25, 2009 at 13:38:18
It works now, thank you so very much !!
Morava

Report •


Ask Question