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

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 6b0df6 in the box below so that we can be sure you are a human.