sample.txt

This is a sample text file.
It contains some lines of text.
We will use grep and regular expressions to search for patterns.
Let's see how it works!

grep_demo

#!/bin/bash
# Demo using `grep` with the `-E` option

# Search for lines containing the word "sample"
grep -E 'sample' sample.txt

# Search for lines starting with the word "It"
grep -E '^It' sample.txt

# Search for lines ending with the word "works!"
grep -E 'works!$' sample.txt

# Search for lines containing either "file" or "text"
grep -E 'file|text' sample.txt

# Search for lines containing the word "text" followed by zero or more characters
grep -E 'text.*' sample.txt

# Search for lines containing the word "sample" followed by any single character
grep -E 'sample.' sample.txt

# Search for lines containing some letters
grep -E '[a-zA-Z]' sample.txt