• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

sed : remove lines between two keywords [ including keywords ]

April 16, 2015 by Sharad Chhetri

The post explains a useful sed command trick to remove all lines between two keywords. The lines which has these keywords will also be removed.

The below given command will show you the output on terminal and do not make any changes inside the file. So it is safe to use as preview output.

sed '/KEYWORD-1/','/KEYWORD-2/d' inputfile

In case you want to save the output in some file use below given syntax

sed '/KEYWORD-1/','/KEYWORD-2/d' inputfile > OutputFile.txt

To directly do the changes in input file.Use the -i switch

sed -i '/KEYWORD-1/','/KEYWORD-2/d' inputfile

Here we would like to show one more example by using pipe and grep command.A good example for linux newbie.

We are using 2 KEYWORDS in below examples –

 ls -l|sed '/orbit-sharad/','/skype-8904/d'

See the reference from our system

sed-command

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. sed command to display text between two strings or keywords
  2. remove html tags by using sed command
  3. grep command to remove blank lines from file
  4. grep command to remove commented lines
  5. Convert hyphen to underscore in between all filenames shell script
  6. 4 Linux commands to get number of lines in file
  7. grep command to show lines after and before the keyword
  8. sed: -e expression #1, char 24: Invalid range end
  9. Convert new line to space by using sed command
  10. Taking file backup while using sed command with -i flag

Filed Under: Linux Tagged With: sed

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

GNU Screen

Change default editor of crontab in Ubuntu

master admin password openerp 7.x

Run the script using nohup without hitting enter key two times

AttributeError: ‘WSGIRequest’ object has no attribute ‘session’ Django python web framework

safest method to remove softlink in linux

Forgot root password ,Reset it in Run level 1

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy