• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Contact
  • Archives
  • Search

Delete lines using sed

December 1, 2021 by Ulysses

How to delete a line containing a pattern using sed.

Contents of test.txt.

$ cat test.txt
one
two
three

$ cat test.txt one two three

Delete a line matching the string “one.”

sed -i '/one/d' test.txt

sed -i '/one/d' test.txt

Display test.txt

$ cat test.txt
two
three

$ cat test.txt two three

Filed Under: Linux Tagged With: delete, line, matching, remove, sed

Search The Website

Subscribe Via Email

Copyright © 2022