Harish Vangavolu
Harish Vangavolu

Reputation: 1025

grep for files through another list of files

I'm trying to find if some java classes are called in a list of script files that are actually being called in a scheduler.

while read j; do
    while read b; do
        #Read through job files
        if [ $(cat crontab.now *.sh | grep -c ./$b) == "1" ] ; then
            echo -e $j: $(cat $b | grep -c .$j) >> bash_output.txt
        fi
    done <UsedBash.txt
done <java_file_names.txt

I want to only look for java file names in scripts that are found at least once in the scheduler. Is there a more efficient way to do this without nested while loops? Also I don't think my if statement works. Thank you.

Upvotes: 2

Views: 75

Answers (2)

Harish Vangavolu
Harish Vangavolu

Reputation: 1025

ANSWER:

input=$(cat UsedBash.txt | tr '\n' ' ')

while read j; do

j=$(echo $j | sed -e 's/\r//g')
#Read through job files
echo $j: $(cat $input | grep -c $j) >> bash_output.txt

done <java_file_names.txt

Upvotes: 0

konsolebox
konsolebox

Reputation: 75478

I don't know how you really want it done but perhaps try this one:

while read j; do
    while read b; do
        [[ $(exec grep -c "/$b" crontab.now *.sh) -ge 1 ]] && \
            echo -e  "$j: $(exec grep -c ".$j" "$b")" >> bash_output.txt
    done < UsedBash.txt
done < java_file_names.txt

Upvotes: 1

Related Questions