bash - How to loop through all files in a directory and find if a value exists in those files using a shell script -
i have directory payment. inside have text files.
xyx.txt agfh.txt hjul.txt i need go through these files , find how many entries in each file contain text bpr.
if it's 1 need alert. example, if xyx.txt contains 1 bpr entry, need alert.
you not need loop, should make it:
grep -l "bpr" /your/path/payment/* greptool find lines matching pattern in files.-lshows files have string."bpr"string looking for./your/path/payment/*meansgrepthroughout files in dir.
in case want want find within specific kind of files / inside directories, because command vary little.
update
based on new requests:
i need go through these files find how many entries in each file bpr.
if 1 need alert. example, if xyx.txt contains 1 bpr entry, need alert.
grep -c friend (more or less). can is:
if [ "$(grep -c a_certain_file)" -eq 1 ]; echo "mai dei mai dei" fi
Comments
Post a Comment