how to remove a specific line in bash/linux?How to remove all the files in a directory?command line, how to...
Where does the expression "triple-A" comes from?
How can I locate a missing person abroad?
Who are the two thieves that appear the opening of Batman: TAS?
Will replacing a fake visa with a different fake visa cause me problems when applying for a legal study permit?
Where can I find vomiting people?
Might have gotten a coworker sick, should I address this?
Writing a worded mathematical expression
How to split a string by the third .(dot) delimiter
Renewed US passport, did not receive expired US passport
Can I disable a battery powered device by reversing half of its batteries?
How to help my 2.5-year-old daughter take her medicine when she refuses to?
Job offer without any details but asking me to withdraw other applications - is it normal?
Can I cast Sunbeam if both my hands are busy?
Random point on a sphere
Are there any space probes or landers which regained communication after being lost?
Sol Ⅲ = Earth: What is the origin of this planetary naming scheme?
ArcMap not displaying attribute table?
Are there any instances of members of different Hogwarts houses coupling up and marrying each other?
SCOTUS - Can Congress overrule Marbury v. Madison by statute?
My research paper filed as a patent in China by my Chinese supervisor without me as inventor
Why does F + F' = 1?
Converting multiple assignment statements to single comma separated assignment
Can I say "I have encrypted something" if I hash something?
Kerning feedback on logo
how to remove a specific line in bash/linux?
How to remove all the files in a directory?command line, how to search a pattern in the first line and delete themHow to remove line if it contains a character exactly onceHow to replace the line with an exact matching of a stringHow can I copy a specific line to a specific folder? - Debian/Bash/LinuxRemove specific words within linesHow to add line in xml fileHow to slice a horizontal tail of a single lineHow to break a line and assign specific string into variables in shellHow to remove part of a line in linux?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
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
linux
add a comment |
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
linux
add a comment |
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
linux
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
linux
linux
asked 3 hours ago
Tree GarenTree Garen
1102 bronze badges
1102 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f540087%2fhow-to-remove-a-specific-line-in-bash-linux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
add a comment |
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
add a comment |
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
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
answered 3 hours ago
Oh My GoodnessOh My Goodness
4203 silver badges8 bronze badges
4203 silver badges8 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f540087%2fhow-to-remove-a-specific-line-in-bash-linux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown