How to remove all matching pattern except the top one in sed?how to remove all double quotes from csv except...
Could a complex system of reaction wheels be used to propel a spacecraft?
Properly unlinking hard links
Should a TA point out a professor's mistake while attending their lecture?
'spazieren' - walking in a silly and affected manner?
Is it good practice to speed up and slow down where not written in a song?
Am I required to correct my opponent's assumptions about my morph creatures?
In Endgame, wouldn't Stark have remembered Hulk busting out of the stairwell?
Do universities maintain secret textbooks?
What's the origin of the concept of alternate dimensions/realities?
Sum and average calculator
How do I portray irrational anger in first person?
Cheap oscilloscope showing 16 MHz square wave
Why don't 3D printer heads use ceramic inner walls?
My colleague treats me like he's my boss, yet we're on the same level
Connecting points from separate Tikz figures
Is the word 'mistake' a concrete or abstract noun?
In what language did Túrin converse with Mím?
Rapid change in character
Understanding data transmission rates over copper wire
New coworker has strange workplace requirements - how should I deal with them?
What caused the end of cybernetic implants?
Can I leave a large suitcase at TPE during a 4-hour layover, and pick it up 4.5 days later when I come back to TPE on my way to Taipei downtown?
What checks exist against overuse of presidential pardons in the USA?
Ask one verbal question to figure out who is blind and who is mute among three persons
How to remove all matching pattern except the top one in sed?
how to remove all double quotes from csv except specific fieldHow do I keep a part of the pattern matched and use it to replace on BSD sed?How to delete everything (in every line) in a text file after a pattern of characters(including the pattern)?sed script to remove all lines with a pattern and append lines at the endHow to use sed and regular expressions to find pattern and remove last few characters?How do i remove a specific pattern from a specific lines using bashsed: delete all lines before matching one, including this one
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
file.txt
1.1.1.1 abc
1.1.1.1 ccc
1.2.2.2 ddd
1.2.2.2 qqq
1.2.2.2 zzz
Expected result:
1.1.1.1 abc
1.2.2.2 ddd
I tried:
sed -i '/1.1.1.1/d' file.txt
sed -i '/2.2.2.2/d' file.txt
But however it remove all instead of leaving 1 result. How to delete all matching pattern but left 1?
linux bash sed scripting
New contributor
add a comment |
file.txt
1.1.1.1 abc
1.1.1.1 ccc
1.2.2.2 ddd
1.2.2.2 qqq
1.2.2.2 zzz
Expected result:
1.1.1.1 abc
1.2.2.2 ddd
I tried:
sed -i '/1.1.1.1/d' file.txt
sed -i '/2.2.2.2/d' file.txt
But however it remove all instead of leaving 1 result. How to delete all matching pattern but left 1?
linux bash sed scripting
New contributor
add a comment |
file.txt
1.1.1.1 abc
1.1.1.1 ccc
1.2.2.2 ddd
1.2.2.2 qqq
1.2.2.2 zzz
Expected result:
1.1.1.1 abc
1.2.2.2 ddd
I tried:
sed -i '/1.1.1.1/d' file.txt
sed -i '/2.2.2.2/d' file.txt
But however it remove all instead of leaving 1 result. How to delete all matching pattern but left 1?
linux bash sed scripting
New contributor
file.txt
1.1.1.1 abc
1.1.1.1 ccc
1.2.2.2 ddd
1.2.2.2 qqq
1.2.2.2 zzz
Expected result:
1.1.1.1 abc
1.2.2.2 ddd
I tried:
sed -i '/1.1.1.1/d' file.txt
sed -i '/2.2.2.2/d' file.txt
But however it remove all instead of leaving 1 result. How to delete all matching pattern but left 1?
linux bash sed scripting
linux bash sed scripting
New contributor
New contributor
New contributor
asked 1 hour ago
Muzaffar MohamedMuzaffar Mohamed
1
1
New contributor
New contributor
add a comment |
add a comment |
0
active
oldest
votes
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/3.0/"u003ecc by-sa 3.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
});
}
});
Muzaffar Mohamed is a new contributor. Be nice, and check out our Code of Conduct.
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%2f538380%2fhow-to-remove-all-matching-pattern-except-the-top-one-in-sed%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Muzaffar Mohamed is a new contributor. Be nice, and check out our Code of Conduct.
Muzaffar Mohamed is a new contributor. Be nice, and check out our Code of Conduct.
Muzaffar Mohamed is a new contributor. Be nice, and check out our Code of Conduct.
Muzaffar Mohamed is a new contributor. Be nice, and check out our Code of Conduct.
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%2f538380%2fhow-to-remove-all-matching-pattern-except-the-top-one-in-sed%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