Bash (Scripting) - do something match does/doesn't begin with pattern

by
Jeremy Canfield |
Updated: March 08 2020
| Bash (Scripting) articles
Let's say file.txt contains the following text.
Hello
World
How
are
you?
The following sed statement can be used to remove lines that do begin with the letter H and then followed by anything.
~]# sed '/^H.*/d' /path/to/file.txt
World
are
you?
Likewise, the following sed statement can be used to remove lines that do not begin with the letter H and then followed by anything.
~]# sed '/^H.*/!d' /path/to/file.txt
Hello
How
Did you find this article helpful?
If so, consider buying me a coffee over at