Using grep in Bash Scripts
📖 Scenario: You work as a system administrator. You often need to find specific words in log files to check system status or errors.Today, you will write a simple bash script that uses grep to search for a word in a text file.
🎯 Goal: Create a bash script that searches for a specific word in a file using grep and shows the matching lines.
📋 What You'll Learn
Create a variable holding the filename
Create a variable holding the search word
Use
grep to find the word in the filePrint the matching lines
💡 Why This Matters
🌍 Real World
System administrators often need to search logs for errors or specific messages quickly using scripts.
💼 Career
Knowing how to use <code>grep</code> in scripts helps automate monitoring and troubleshooting tasks in IT jobs.
Progress0 / 4 steps