how to remove a specific line in bash/linux?

Tree Garen

say I am given this file

username1
username2
username3

I want to delete a line that contains something I say. Like for example:

$ deletestuff abovefile username2
$ cat file
username1
username3
Oh My Goodness

Use sed -i to edit in place. /regexp/d deletes lines matching regexp.

sed -i /username2/d file

To match whole lines (so that, for example, username222 is not also removed) use ^ and $ to anchor the search to start and end of the line.

sed -i '/^username2$/d' file

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to remove a specific line that contains a specific string?

How to remove a specific, duplicated line within a file?

How to remove the rest of the line after a specific string

How to remove lines with specific pattern and next line

How to remove line with specific string from file

How to remove / just from a specific line?

How to remove specific line from multi-line string

How to remove a blank line in text file after deleting a specific line?

How can i filter/remove a line that a specific word is not exist in the line?

How to delete (remove) a specific line of a text file based on the line number?

How to remove specific empty lines from multi line strings in python?

How to remove commas in the middle of a specific line in a file in linux/unix

How to remove line matching specific pattern from a file

How to use Pattern, Matcher in Java regex API to remove a specific line

How to remove line containing a specific string from file?

How to remove command-line history from a specific time period?

how to remove the last li::after for first line in specific width of an div

How to create a regex pattern to remove line breaks after specific tag

How do I remove a specific line from a text file in python

How to remove a specific character in a string but only if there are no numbers in that line in Linux

How to remove a line in notepad++ that has a specific character in it?

How to remove every line starting with specific string from log file?

How to remove a line from csv file if it contains a specific word

How to remove a line containing two specific string in text?

How to append a string to one specific line and remove a string from another specific line in a file?

Remove specific log line in Android

Remove duplicate strings in specific line

How to remove a specific line in dart as per given line number starting from 0

How to remove the first character in a line which contains a specific string from Linux command line?