I 'm writing a script to search particular strings from log files. The log file contains lines start with *. The file may contain many other lines start with *. I need to search a particular line from my log file. The grep command is working in command line , but when i run my script, Its printing all files in that directory . ( Example : script1.shScript2.shMessage CompletedScript4.sh)
Any suggestions?
Ex:
************Message Completed
tail -F file.log | while read LINE
do
echo $LINE | awk '{print $0}' | grep "[\*]*.Message Completed*" >>$TestFile
done
grep "[\*]*.Message Completed*" # Matches "Message Complete" preceded by an arbitrary character (.) and followed by zero
# or more d's after the sentence. The matching of the literal backslash or the asterisk ([\*])
# has no meaning here, because it is followed by an asterisk, which means zero or more times
# so it will match, whether or not these characters are present
grep "[*]Message Completed[*]" # Matches "Message Completed" followed by an asterisk directly before and after the sentence
grep "[*].*Message Completed.*[*]" # Matches "Message Completed" followed by an asterisk somewhere before and after the sentence
grep uses BRE (Basic Regular Expressions) and not Unix Pattern Matching, which use a different syntax
Please learn how to use CODE tags (and not ICODE tags)