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/* 
  • grep tool find lines matching pattern in files.
  • -l shows files have string.
  • "bpr" string looking for.
  • /your/path/payment/* means grep throughout 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

Popular posts from this blog

iphone - Three second countdown in cocos2d -

hyperlink - how to do url routing in php -

c - Avoiding Extra Malloc in Linked List (node->next = NULL) -