Jon
Jon

Reputation: 95

String comparison issue in bash script

I wrote the bellow script the purpose of the script is to find all files that start with foo and are no older 3 days sort them then compare them against the list of files in the list file. And to repot only files that are missing. The problem with my script is that it doesn’t not take in to account a missing file ie see below example Let’s say my file called list contains foo1, foo2, foo3, foo4, foo5 but in the event that one file files is missing the string comparison is off. Ie if file foo4 is missing when the script is ran foo5 would be compared foo4

Hope that makes sense

enter  

#!/bin/bash
Set –x
Find ~/test99 –name “foo*” –mtime -3 –print>report
Sort report –o report;
Cat report|cut -c 22-25>report1;
while read comp1<&3 && read comp2<&4
do
    if [[ $comp1 = $comp2 ]]; then
    echo "file not found" >/dev/null
else
    echo "$comp1 not found"
fi
done 3<report1 4<list

Upvotes: 0

Views: 132

Answers (1)

Zolt&#225;n Haindrich
Zolt&#225;n Haindrich

Reputation: 1808

you might want to use diff for comparing the lists

or you can use fgrep -vf report list to get the difference between list and report

Upvotes: 1

Related Questions