I am working on a course project ! And homework text is as below :
Write a shell script that takes a word and a number as arguments. Then it checks all files in your current directory, and finds out the files which include the given word at least the given number of times.
Sample output should be :
$myprog3.sh write 2
The file "./file-comp.sh" contains the word "write" 3 times.
The file "./homework.log" contains the word "write" 11 times.
I wrote some of the code but im having problem while reading the filenames into an array.
count=`find . -type f -exec grep -H $word {} \; | wc -l`
read -a filearray <<< `find . -type f -exec grep -l "$word" {} \;`
read -a numarray <<< `find . -type f -exec grep -c "$word" {} \;`
size=${#filearray[@]}
echo "Array size is "$size""
for x in `seq 0 $size`
do
echo $x
echo "${filearray[x]}"
done
Output seems like this :
Array size is 5
0
./UntitledDocument.tex~
1
./Untitled
2
Document.tex
3
./wordcounter.sh
4
./wordcounter.sh~
5
For ex: it should seem like Untitled Document.tex instead of
Untitled
Document.tex
How can i fix it?
And also for the full question could you please offer me a solution? Thanks in advance..