Author Name: Ilias Loukopoulos
This Bash script is designed to analyze a log file and count the occurrences of the word "ERROR" within it. The script takes a log file named random.log
as input, searches for the word "ERROR," and then outputs the number of occurrences.
To use the script, follow these steps:
-
Ensure that the script has execute permissions. If not, run the following command:
chmod +x script_name.sh
-
Execute the script:
./script_name.sh
-
The script will display the number of times the word "ERROR" appears in the
random.log
file.
The script expects a log file with entries in the following format:
YYYY-MM-DD HH:mm:ss LEVEL: Log message
YYYY-MM-DD HH:mm:ss LEVEL: Log message
YYYY-MM-DD: Date in the format Year-Month-Day.
The script outputs a message indicating the number of occurrences of the word "ERROR" in the log file:
ERROR word appears 5 times in the random.log file
- The script uses the
grep
command to search for the word "ERROR" in the log file and then utilizeswc -l
to count the occurrences. - Ensure that the log file (
random.log
) is present in the same directory as the script or provide the full path if located elsewhere.