Bootstrap FreeKB - Bash (Scripting) - do something every other match
Bash (Scripting) - do something every other match

Updated:   |  Bash (Scripting) articles

Let's say file.txt contains the following text.

Hello
Hello
World
World
How
How
are
are
you?
you?

 


Delete a specific line

The following command will remove a specific line. In this example, line 5 is removed.

~]# sed -i 5d /path/to/file.txt

 

The result of the command will be:

Hello
Hello
World
World
How
are
are
you?
you?

 

 


Remove every other line

The following sed command will remove every other line of text from the file.

~]# sed -i '1~3d' /path/to/file.txt

 

The result of the command will be:

Hello
World
How
are
you
today?

 




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 884f58 in the box below so that we can be sure you are a human.