Output only certain fields
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom: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,
text-processing awk sed
add a comment |
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
Don'tcat file | sed 'stuff'
; justsed 'stuff' file
.
– DopeGhoti
Aug 29 '17 at 20:20
add a comment |
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
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
text-processing awk sed
edited 5 hours ago
Rui F Ribeiro
41.9k1483142
41.9k1483142
asked Aug 29 '17 at 20:13
ErnieErnie
2216
2216
Don'tcat file | sed 'stuff'
; justsed 'stuff' file
.
– DopeGhoti
Aug 29 '17 at 20:20
add a comment |
Don'tcat file | sed 'stuff'
; justsed '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
add a comment |
1 Answer
1
active
oldest
votes
$ 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.
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
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%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
$ 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.
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
add a comment |
$ 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.
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
add a comment |
$ 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.
$ 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.
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
add a comment |
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
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%2f389149%2foutput-only-certain-fields%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
Don't
cat file | sed 'stuff'
; justsed 'stuff' file
.– DopeGhoti
Aug 29 '17 at 20:20