listing within a folder and display success message upon matching pattern
i want to write a script which check within a folder and check for specific pattern upon a file is matched it should give me a success message.
for example a folder test contains file1 file2 file3 and onward. scripts should check for all files in test and if file1 is present it should give me the success message. thanks and regards. |
So what have you done already and where do you have problems?
|
i do not know how to have loop on directory?
|
You don't need a loop for doing this. Have a look at the find command, that is what you are looking for. For example:
Code:
find $DIRECTORY -name "$PATTERN" For more information look at Code:
man find |
thanks for the great hint. but find produced the one part that it sorted out looking into the directory and match the pattern.
i want that if i got file1 in the result it should give some sort of message. i found that exec switch would be helpful in this case but don't know how i can implement some condition within a find command. thanks in advance. |
You don't do that in the find command. Find is printing one line per matching file to stdout. Just count the lines. If the number of lines is 0 then no match was found, if it is greater than 0 there were matches.
To store the number of lines just pipe the output of find through wc -l: Code:
LINES=$(find $DIRECTORY -name "$PATTERN" | wc -l) |
All times are GMT -5. The time now is 06:13 AM. |