Loop through text file and execute If Then statement for each line with bash -
i have command lists full 8 level deep path of folders backing up. have command enumerates 8 level deep folders on system. both of these stored variables in bash script.
i'm trying loop takes file 1 , uses first line entry variable in if/then/else, , moves onwards through end of file.
i've tried many things beyond skillset provide example won't confuse reader of post.
tempfile1=/ifs/data/scripts/configmonitor/tempfile1.txt tempfile2=/ifs/data/scripts/configmonitor/tempfile2.txt find /ifs/*/*/backup -maxdepth 4 -mindepth 4 -type d > $tempfile1 isi snapshot schedules list -v | grep path: | awk '{print $2}' > $tempfile2 list line 1 on $tempfile1 grep line 1 within $tempfile2 if result yielded echo found else echo fullpath not being backed fi
use grep's -f flag
grep(1) says:
-f file, --file=file obtain patterns file, 1 per line. empty file contains 0 patterns, , therefore matches nothing. (-f specified posix.) therefore, following should work:
grep -f patterns_to_match.txt file_to_examine.txt faster reporting
another way think can ask gnu grep show matches:
echo 'lines match pattern in pattern file.' grep -f patterns_to_match.txt file_to_examine.txt and show lines don't match of patterns:
echo 'lines not match patterns in pattern file.' grep -f patterns_to_match.txt -v file_to_examine.txt this faster , more efficient looping through file 1 line @ time in bash. may or may not similar results grep other gnu grep; while -f , -v flags specified posix, tested against gnu grep 2.16, mileage may vary.
Comments
Post a Comment