Isolate portion of line from log file, then print to screen
Clash Royale CLAN TAG#URR8PPP
If I have a file that updates a record count every 5 minutes, the output looks something like this:
timestamp name of log file dataset record count 8600
timestamp name of log file dataset record count 8610
How can I effectively isolate dataset record count XXXX
and print just that string to screen?
grep
add a comment |
If I have a file that updates a record count every 5 minutes, the output looks something like this:
timestamp name of log file dataset record count 8600
timestamp name of log file dataset record count 8610
How can I effectively isolate dataset record count XXXX
and print just that string to screen?
grep
from a file, or from a command? Just that textdataset record count (etc)
or only the matching (entire) lines?
– Jeff Schaller
Jan 17 at 16:47
Just that portion of the log file line. Not the entire line itself
– GreNIX
Jan 17 at 16:48
Are you using an Operating System whose grep supports the-o
flag? (GNU/Linux systems, mainly)
– Jeff Schaller
Jan 17 at 16:52
Rhel 7. I've attempted using-o
, but admittedly I'm confused by the man page entry for it and may not be using it properly. Seems a bit convoluted to me.
– GreNIX
Jan 17 at 16:53
Sorry, -o man page isn't confusing; -w is.
– GreNIX
Jan 17 at 16:56
add a comment |
If I have a file that updates a record count every 5 minutes, the output looks something like this:
timestamp name of log file dataset record count 8600
timestamp name of log file dataset record count 8610
How can I effectively isolate dataset record count XXXX
and print just that string to screen?
grep
If I have a file that updates a record count every 5 minutes, the output looks something like this:
timestamp name of log file dataset record count 8600
timestamp name of log file dataset record count 8610
How can I effectively isolate dataset record count XXXX
and print just that string to screen?
grep
grep
asked Jan 17 at 16:45
GreNIX GreNIX
597
597
from a file, or from a command? Just that textdataset record count (etc)
or only the matching (entire) lines?
– Jeff Schaller
Jan 17 at 16:47
Just that portion of the log file line. Not the entire line itself
– GreNIX
Jan 17 at 16:48
Are you using an Operating System whose grep supports the-o
flag? (GNU/Linux systems, mainly)
– Jeff Schaller
Jan 17 at 16:52
Rhel 7. I've attempted using-o
, but admittedly I'm confused by the man page entry for it and may not be using it properly. Seems a bit convoluted to me.
– GreNIX
Jan 17 at 16:53
Sorry, -o man page isn't confusing; -w is.
– GreNIX
Jan 17 at 16:56
add a comment |
from a file, or from a command? Just that textdataset record count (etc)
or only the matching (entire) lines?
– Jeff Schaller
Jan 17 at 16:47
Just that portion of the log file line. Not the entire line itself
– GreNIX
Jan 17 at 16:48
Are you using an Operating System whose grep supports the-o
flag? (GNU/Linux systems, mainly)
– Jeff Schaller
Jan 17 at 16:52
Rhel 7. I've attempted using-o
, but admittedly I'm confused by the man page entry for it and may not be using it properly. Seems a bit convoluted to me.
– GreNIX
Jan 17 at 16:53
Sorry, -o man page isn't confusing; -w is.
– GreNIX
Jan 17 at 16:56
from a file, or from a command? Just that text
dataset record count (etc)
or only the matching (entire) lines?– Jeff Schaller
Jan 17 at 16:47
from a file, or from a command? Just that text
dataset record count (etc)
or only the matching (entire) lines?– Jeff Schaller
Jan 17 at 16:47
Just that portion of the log file line. Not the entire line itself
– GreNIX
Jan 17 at 16:48
Just that portion of the log file line. Not the entire line itself
– GreNIX
Jan 17 at 16:48
Are you using an Operating System whose grep supports the
-o
flag? (GNU/Linux systems, mainly)– Jeff Schaller
Jan 17 at 16:52
Are you using an Operating System whose grep supports the
-o
flag? (GNU/Linux systems, mainly)– Jeff Schaller
Jan 17 at 16:52
Rhel 7. I've attempted using
-o
, but admittedly I'm confused by the man page entry for it and may not be using it properly. Seems a bit convoluted to me.– GreNIX
Jan 17 at 16:53
Rhel 7. I've attempted using
-o
, but admittedly I'm confused by the man page entry for it and may not be using it properly. Seems a bit convoluted to me.– GreNIX
Jan 17 at 16:53
Sorry, -o man page isn't confusing; -w is.
– GreNIX
Jan 17 at 16:56
Sorry, -o man page isn't confusing; -w is.
– GreNIX
Jan 17 at 16:56
add a comment |
1 Answer
1
active
oldest
votes
One way, with awk:
awk 'match($0, "dataset record count [[:digit:]]+") print substr($0, RSTART, RLENGTH) ' input
or piped via:
command | awk 'match($0, "dataset record count [[:digit:]]+") print substr($0, RSTART, RLENGTH) '
Or with a grep that accepts -o
:
grep -Eo 'dataset record count [[:digit:]]+' input
or piped:
command | grep -Eo 'dataset record count [[:digit:]]+'
I've triedgrep -Eo 'dataset [a-z A-Z 0-9]'
but I'm not sure why it isn't working.
– GreNIX
Jan 17 at 17:05
I needed to add the + to the end of the bracket
– GreNIX
Jan 17 at 17:06
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%2f495115%2fisolate-portion-of-line-from-log-file-then-print-to-screen%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
One way, with awk:
awk 'match($0, "dataset record count [[:digit:]]+") print substr($0, RSTART, RLENGTH) ' input
or piped via:
command | awk 'match($0, "dataset record count [[:digit:]]+") print substr($0, RSTART, RLENGTH) '
Or with a grep that accepts -o
:
grep -Eo 'dataset record count [[:digit:]]+' input
or piped:
command | grep -Eo 'dataset record count [[:digit:]]+'
I've triedgrep -Eo 'dataset [a-z A-Z 0-9]'
but I'm not sure why it isn't working.
– GreNIX
Jan 17 at 17:05
I needed to add the + to the end of the bracket
– GreNIX
Jan 17 at 17:06
add a comment |
One way, with awk:
awk 'match($0, "dataset record count [[:digit:]]+") print substr($0, RSTART, RLENGTH) ' input
or piped via:
command | awk 'match($0, "dataset record count [[:digit:]]+") print substr($0, RSTART, RLENGTH) '
Or with a grep that accepts -o
:
grep -Eo 'dataset record count [[:digit:]]+' input
or piped:
command | grep -Eo 'dataset record count [[:digit:]]+'
I've triedgrep -Eo 'dataset [a-z A-Z 0-9]'
but I'm not sure why it isn't working.
– GreNIX
Jan 17 at 17:05
I needed to add the + to the end of the bracket
– GreNIX
Jan 17 at 17:06
add a comment |
One way, with awk:
awk 'match($0, "dataset record count [[:digit:]]+") print substr($0, RSTART, RLENGTH) ' input
or piped via:
command | awk 'match($0, "dataset record count [[:digit:]]+") print substr($0, RSTART, RLENGTH) '
Or with a grep that accepts -o
:
grep -Eo 'dataset record count [[:digit:]]+' input
or piped:
command | grep -Eo 'dataset record count [[:digit:]]+'
One way, with awk:
awk 'match($0, "dataset record count [[:digit:]]+") print substr($0, RSTART, RLENGTH) ' input
or piped via:
command | awk 'match($0, "dataset record count [[:digit:]]+") print substr($0, RSTART, RLENGTH) '
Or with a grep that accepts -o
:
grep -Eo 'dataset record count [[:digit:]]+' input
or piped:
command | grep -Eo 'dataset record count [[:digit:]]+'
answered Jan 17 at 16:55
Jeff SchallerJeff Schaller
40.8k1056129
40.8k1056129
I've triedgrep -Eo 'dataset [a-z A-Z 0-9]'
but I'm not sure why it isn't working.
– GreNIX
Jan 17 at 17:05
I needed to add the + to the end of the bracket
– GreNIX
Jan 17 at 17:06
add a comment |
I've triedgrep -Eo 'dataset [a-z A-Z 0-9]'
but I'm not sure why it isn't working.
– GreNIX
Jan 17 at 17:05
I needed to add the + to the end of the bracket
– GreNIX
Jan 17 at 17:06
I've tried
grep -Eo 'dataset [a-z A-Z 0-9]'
but I'm not sure why it isn't working.– GreNIX
Jan 17 at 17:05
I've tried
grep -Eo 'dataset [a-z A-Z 0-9]'
but I'm not sure why it isn't working.– GreNIX
Jan 17 at 17:05
I needed to add the + to the end of the bracket
– GreNIX
Jan 17 at 17:06
I needed to add the + to the end of the bracket
– GreNIX
Jan 17 at 17:06
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%2f495115%2fisolate-portion-of-line-from-log-file-then-print-to-screen%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
from a file, or from a command? Just that text
dataset record count (etc)
or only the matching (entire) lines?– Jeff Schaller
Jan 17 at 16:47
Just that portion of the log file line. Not the entire line itself
– GreNIX
Jan 17 at 16:48
Are you using an Operating System whose grep supports the
-o
flag? (GNU/Linux systems, mainly)– Jeff Schaller
Jan 17 at 16:52
Rhel 7. I've attempted using
-o
, but admittedly I'm confused by the man page entry for it and may not be using it properly. Seems a bit convoluted to me.– GreNIX
Jan 17 at 16:53
Sorry, -o man page isn't confusing; -w is.
– GreNIX
Jan 17 at 16:56