sed search and show matching pattern, removing the rest
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to clean a list containing packages. I wish to remove the package revisions, leaving the package names only.
I see every package has naming convention like this: package-name-majorver-minorver , etc: openssl-1.0.1e-57.0.5.el6 . I want openssl only, not -1.0.1e-57.0.5.el6
So far I have this sed 's/^.*-//'
, but this doesn't work obviously.
sed package-management rpm
add a comment |
I am trying to clean a list containing packages. I wish to remove the package revisions, leaving the package names only.
I see every package has naming convention like this: package-name-majorver-minorver , etc: openssl-1.0.1e-57.0.5.el6 . I want openssl only, not -1.0.1e-57.0.5.el6
So far I have this sed 's/^.*-//'
, but this doesn't work obviously.
sed package-management rpm
watch out for package names with dashes! If you're gathering the list with RPM, consider using the --queryformat to get the %NAME separately.
– Jeff Schaller♦
Mar 13 at 11:05
add a comment |
I am trying to clean a list containing packages. I wish to remove the package revisions, leaving the package names only.
I see every package has naming convention like this: package-name-majorver-minorver , etc: openssl-1.0.1e-57.0.5.el6 . I want openssl only, not -1.0.1e-57.0.5.el6
So far I have this sed 's/^.*-//'
, but this doesn't work obviously.
sed package-management rpm
I am trying to clean a list containing packages. I wish to remove the package revisions, leaving the package names only.
I see every package has naming convention like this: package-name-majorver-minorver , etc: openssl-1.0.1e-57.0.5.el6 . I want openssl only, not -1.0.1e-57.0.5.el6
So far I have this sed 's/^.*-//'
, but this doesn't work obviously.
sed package-management rpm
sed package-management rpm
asked Mar 13 at 9:49
user121392user121392
85
85
watch out for package names with dashes! If you're gathering the list with RPM, consider using the --queryformat to get the %NAME separately.
– Jeff Schaller♦
Mar 13 at 11:05
add a comment |
watch out for package names with dashes! If you're gathering the list with RPM, consider using the --queryformat to get the %NAME separately.
– Jeff Schaller♦
Mar 13 at 11:05
watch out for package names with dashes! If you're gathering the list with RPM, consider using the --queryformat to get the %NAME separately.
– Jeff Schaller♦
Mar 13 at 11:05
watch out for package names with dashes! If you're gathering the list with RPM, consider using the --queryformat to get the %NAME separately.
– Jeff Schaller♦
Mar 13 at 11:05
add a comment |
3 Answers
3
active
oldest
votes
If the package name always has two version number parts appended, separated by hyphens, and if the version parts never contain a hyphen, you can use this command
sed 's/-[^-]*-[^-]*$//'
This will remove two hyphens, each followed by 0 or more non-hyphen characters, at the end of the line ($
). It would also change e.g. foo-bar-baz--
to foo-bar-baz
.
add a comment |
If the package name doesn't contain -
, this should work:
sed -r 's/([^-]+).*/1/'
unfortunately, it does, and the number of - 's are inconsistent too, eg: tmux and python-pip, the only consistent ones are major ver and minor ver appended to back separated by -
– user121392
Mar 13 at 10:10
add a comment |
Well I know it's not the best solution, but I found this https://stackoverflow.com/a/51153277/5227747, so the solution was
cat file | sed 's/ // ; s/-/t/' | rev | cut -f 3- | rev | sed 's/t/-/'
it removes the last two '-'-separated columns without fuss, if anyone knows how to do it better I would love to know.
Unneccessarycat
– Weijun Zhou
Mar 13 at 10:57
I have to read from a file. I will check sed to improve the command
– user121392
Mar 13 at 11:49
You should almost always dosed ... file
instead ofcat file | sed ...
– Weijun Zhou
Mar 13 at 22:19
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/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
);
);
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%2f506048%2fsed-search-and-show-matching-pattern-removing-the-rest%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
If the package name always has two version number parts appended, separated by hyphens, and if the version parts never contain a hyphen, you can use this command
sed 's/-[^-]*-[^-]*$//'
This will remove two hyphens, each followed by 0 or more non-hyphen characters, at the end of the line ($
). It would also change e.g. foo-bar-baz--
to foo-bar-baz
.
add a comment |
If the package name always has two version number parts appended, separated by hyphens, and if the version parts never contain a hyphen, you can use this command
sed 's/-[^-]*-[^-]*$//'
This will remove two hyphens, each followed by 0 or more non-hyphen characters, at the end of the line ($
). It would also change e.g. foo-bar-baz--
to foo-bar-baz
.
add a comment |
If the package name always has two version number parts appended, separated by hyphens, and if the version parts never contain a hyphen, you can use this command
sed 's/-[^-]*-[^-]*$//'
This will remove two hyphens, each followed by 0 or more non-hyphen characters, at the end of the line ($
). It would also change e.g. foo-bar-baz--
to foo-bar-baz
.
If the package name always has two version number parts appended, separated by hyphens, and if the version parts never contain a hyphen, you can use this command
sed 's/-[^-]*-[^-]*$//'
This will remove two hyphens, each followed by 0 or more non-hyphen characters, at the end of the line ($
). It would also change e.g. foo-bar-baz--
to foo-bar-baz
.
answered Mar 13 at 10:45
BodoBodo
2,271618
2,271618
add a comment |
add a comment |
If the package name doesn't contain -
, this should work:
sed -r 's/([^-]+).*/1/'
unfortunately, it does, and the number of - 's are inconsistent too, eg: tmux and python-pip, the only consistent ones are major ver and minor ver appended to back separated by -
– user121392
Mar 13 at 10:10
add a comment |
If the package name doesn't contain -
, this should work:
sed -r 's/([^-]+).*/1/'
unfortunately, it does, and the number of - 's are inconsistent too, eg: tmux and python-pip, the only consistent ones are major ver and minor ver appended to back separated by -
– user121392
Mar 13 at 10:10
add a comment |
If the package name doesn't contain -
, this should work:
sed -r 's/([^-]+).*/1/'
If the package name doesn't contain -
, this should work:
sed -r 's/([^-]+).*/1/'
answered Mar 13 at 10:06
CharlesCharles
335110
335110
unfortunately, it does, and the number of - 's are inconsistent too, eg: tmux and python-pip, the only consistent ones are major ver and minor ver appended to back separated by -
– user121392
Mar 13 at 10:10
add a comment |
unfortunately, it does, and the number of - 's are inconsistent too, eg: tmux and python-pip, the only consistent ones are major ver and minor ver appended to back separated by -
– user121392
Mar 13 at 10:10
unfortunately, it does, and the number of - 's are inconsistent too, eg: tmux and python-pip, the only consistent ones are major ver and minor ver appended to back separated by -
– user121392
Mar 13 at 10:10
unfortunately, it does, and the number of - 's are inconsistent too, eg: tmux and python-pip, the only consistent ones are major ver and minor ver appended to back separated by -
– user121392
Mar 13 at 10:10
add a comment |
Well I know it's not the best solution, but I found this https://stackoverflow.com/a/51153277/5227747, so the solution was
cat file | sed 's/ // ; s/-/t/' | rev | cut -f 3- | rev | sed 's/t/-/'
it removes the last two '-'-separated columns without fuss, if anyone knows how to do it better I would love to know.
Unneccessarycat
– Weijun Zhou
Mar 13 at 10:57
I have to read from a file. I will check sed to improve the command
– user121392
Mar 13 at 11:49
You should almost always dosed ... file
instead ofcat file | sed ...
– Weijun Zhou
Mar 13 at 22:19
add a comment |
Well I know it's not the best solution, but I found this https://stackoverflow.com/a/51153277/5227747, so the solution was
cat file | sed 's/ // ; s/-/t/' | rev | cut -f 3- | rev | sed 's/t/-/'
it removes the last two '-'-separated columns without fuss, if anyone knows how to do it better I would love to know.
Unneccessarycat
– Weijun Zhou
Mar 13 at 10:57
I have to read from a file. I will check sed to improve the command
– user121392
Mar 13 at 11:49
You should almost always dosed ... file
instead ofcat file | sed ...
– Weijun Zhou
Mar 13 at 22:19
add a comment |
Well I know it's not the best solution, but I found this https://stackoverflow.com/a/51153277/5227747, so the solution was
cat file | sed 's/ // ; s/-/t/' | rev | cut -f 3- | rev | sed 's/t/-/'
it removes the last two '-'-separated columns without fuss, if anyone knows how to do it better I would love to know.
Well I know it's not the best solution, but I found this https://stackoverflow.com/a/51153277/5227747, so the solution was
cat file | sed 's/ // ; s/-/t/' | rev | cut -f 3- | rev | sed 's/t/-/'
it removes the last two '-'-separated columns without fuss, if anyone knows how to do it better I would love to know.
answered Mar 13 at 10:33
user121392user121392
85
85
Unneccessarycat
– Weijun Zhou
Mar 13 at 10:57
I have to read from a file. I will check sed to improve the command
– user121392
Mar 13 at 11:49
You should almost always dosed ... file
instead ofcat file | sed ...
– Weijun Zhou
Mar 13 at 22:19
add a comment |
Unneccessarycat
– Weijun Zhou
Mar 13 at 10:57
I have to read from a file. I will check sed to improve the command
– user121392
Mar 13 at 11:49
You should almost always dosed ... file
instead ofcat file | sed ...
– Weijun Zhou
Mar 13 at 22:19
Unneccessary
cat
– Weijun Zhou
Mar 13 at 10:57
Unneccessary
cat
– Weijun Zhou
Mar 13 at 10:57
I have to read from a file. I will check sed to improve the command
– user121392
Mar 13 at 11:49
I have to read from a file. I will check sed to improve the command
– user121392
Mar 13 at 11:49
You should almost always do
sed ... file
instead of cat file | sed ...
– Weijun Zhou
Mar 13 at 22:19
You should almost always do
sed ... file
instead of cat file | sed ...
– Weijun Zhou
Mar 13 at 22:19
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%2f506048%2fsed-search-and-show-matching-pattern-removing-the-rest%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
watch out for package names with dashes! If you're gathering the list with RPM, consider using the --queryformat to get the %NAME separately.
– Jeff Schaller♦
Mar 13 at 11:05