Output only certain fields





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















Been looking for a way to output a certain field in a line, and only the next field after it.



So say I have file with the contents "blue, green, purple, orange, black, white, ", how would I search for the word "purple, ", and print to screen only "purple, orange,".



I need to omit the "black, white," from the output.



cat filename | sed -n -e 's/^.*(purple)/1/p'
purple, orange, black, white,









share|improve this question

























  • Don't cat file | sed 'stuff'; just sed 'stuff' file.

    – DopeGhoti
    Aug 29 '17 at 20:20




















0















Been looking for a way to output a certain field in a line, and only the next field after it.



So say I have file with the contents "blue, green, purple, orange, black, white, ", how would I search for the word "purple, ", and print to screen only "purple, orange,".



I need to omit the "black, white," from the output.



cat filename | sed -n -e 's/^.*(purple)/1/p'
purple, orange, black, white,









share|improve this question

























  • Don't cat file | sed 'stuff'; just sed 'stuff' file.

    – DopeGhoti
    Aug 29 '17 at 20:20
















0












0








0








Been looking for a way to output a certain field in a line, and only the next field after it.



So say I have file with the contents "blue, green, purple, orange, black, white, ", how would I search for the word "purple, ", and print to screen only "purple, orange,".



I need to omit the "black, white," from the output.



cat filename | sed -n -e 's/^.*(purple)/1/p'
purple, orange, black, white,









share|improve this question
















Been looking for a way to output a certain field in a line, and only the next field after it.



So say I have file with the contents "blue, green, purple, orange, black, white, ", how would I search for the word "purple, ", and print to screen only "purple, orange,".



I need to omit the "black, white," from the output.



cat filename | sed -n -e 's/^.*(purple)/1/p'
purple, orange, black, white,






text-processing awk sed






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 5 hours ago









Rui F Ribeiro

41.9k1483142




41.9k1483142










asked Aug 29 '17 at 20:13









ErnieErnie

2216




2216













  • Don't cat file | sed 'stuff'; just sed 'stuff' file.

    – DopeGhoti
    Aug 29 '17 at 20:20





















  • Don't cat file | sed 'stuff'; just sed 'stuff' file.

    – DopeGhoti
    Aug 29 '17 at 20:20



















Don't cat file | sed 'stuff'; just sed 'stuff' file.

– DopeGhoti
Aug 29 '17 at 20:20







Don't cat file | sed 'stuff'; just sed 'stuff' file.

– DopeGhoti
Aug 29 '17 at 20:20












1 Answer
1






active

oldest

votes


















4














$ grep -o 'purple, [^,]*' input
purple, orange


The -o switch prints only the string matching the pattern.



The pattern is the string purple,, followed by zero or more characters which are anything other than a comma.






share|improve this answer
























  • Exactly what I was looking forward. Thanks DopeGhoti :)

    – Ernie
    Aug 29 '17 at 20:21






  • 1





    Glad to hear it! When you have a moment, please mark the answer as 'Accepted' so that others know the question is no longer seeking an answer. Welcome to Stack Exchange!

    – DopeGhoti
    Aug 29 '17 at 20:22











  • Done. Thanks again. First time questioner so still learning the ropes on this forum.

    – Ernie
    Aug 29 '17 at 21:28












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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f389149%2foutput-only-certain-fields%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









4














$ grep -o 'purple, [^,]*' input
purple, orange


The -o switch prints only the string matching the pattern.



The pattern is the string purple,, followed by zero or more characters which are anything other than a comma.






share|improve this answer
























  • Exactly what I was looking forward. Thanks DopeGhoti :)

    – Ernie
    Aug 29 '17 at 20:21






  • 1





    Glad to hear it! When you have a moment, please mark the answer as 'Accepted' so that others know the question is no longer seeking an answer. Welcome to Stack Exchange!

    – DopeGhoti
    Aug 29 '17 at 20:22











  • Done. Thanks again. First time questioner so still learning the ropes on this forum.

    – Ernie
    Aug 29 '17 at 21:28
















4














$ grep -o 'purple, [^,]*' input
purple, orange


The -o switch prints only the string matching the pattern.



The pattern is the string purple,, followed by zero or more characters which are anything other than a comma.






share|improve this answer
























  • Exactly what I was looking forward. Thanks DopeGhoti :)

    – Ernie
    Aug 29 '17 at 20:21






  • 1





    Glad to hear it! When you have a moment, please mark the answer as 'Accepted' so that others know the question is no longer seeking an answer. Welcome to Stack Exchange!

    – DopeGhoti
    Aug 29 '17 at 20:22











  • Done. Thanks again. First time questioner so still learning the ropes on this forum.

    – Ernie
    Aug 29 '17 at 21:28














4












4








4







$ grep -o 'purple, [^,]*' input
purple, orange


The -o switch prints only the string matching the pattern.



The pattern is the string purple,, followed by zero or more characters which are anything other than a comma.






share|improve this answer













$ grep -o 'purple, [^,]*' input
purple, orange


The -o switch prints only the string matching the pattern.



The pattern is the string purple,, followed by zero or more characters which are anything other than a comma.







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 29 '17 at 20:18









DopeGhotiDopeGhoti

46.8k56190




46.8k56190













  • Exactly what I was looking forward. Thanks DopeGhoti :)

    – Ernie
    Aug 29 '17 at 20:21






  • 1





    Glad to hear it! When you have a moment, please mark the answer as 'Accepted' so that others know the question is no longer seeking an answer. Welcome to Stack Exchange!

    – DopeGhoti
    Aug 29 '17 at 20:22











  • Done. Thanks again. First time questioner so still learning the ropes on this forum.

    – Ernie
    Aug 29 '17 at 21:28



















  • Exactly what I was looking forward. Thanks DopeGhoti :)

    – Ernie
    Aug 29 '17 at 20:21






  • 1





    Glad to hear it! When you have a moment, please mark the answer as 'Accepted' so that others know the question is no longer seeking an answer. Welcome to Stack Exchange!

    – DopeGhoti
    Aug 29 '17 at 20:22











  • Done. Thanks again. First time questioner so still learning the ropes on this forum.

    – Ernie
    Aug 29 '17 at 21:28

















Exactly what I was looking forward. Thanks DopeGhoti :)

– Ernie
Aug 29 '17 at 20:21





Exactly what I was looking forward. Thanks DopeGhoti :)

– Ernie
Aug 29 '17 at 20:21




1




1





Glad to hear it! When you have a moment, please mark the answer as 'Accepted' so that others know the question is no longer seeking an answer. Welcome to Stack Exchange!

– DopeGhoti
Aug 29 '17 at 20:22





Glad to hear it! When you have a moment, please mark the answer as 'Accepted' so that others know the question is no longer seeking an answer. Welcome to Stack Exchange!

– DopeGhoti
Aug 29 '17 at 20:22













Done. Thanks again. First time questioner so still learning the ropes on this forum.

– Ernie
Aug 29 '17 at 21:28





Done. Thanks again. First time questioner so still learning the ropes on this forum.

– Ernie
Aug 29 '17 at 21:28


















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f389149%2foutput-only-certain-fields%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

濃尾地震

How to rewrite equation of hyperbola in standard form

No ethernet ip address in my vocore2