Isolate portion of line from log file, then print to screen
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
15 hours ago
Just that portion of the log file line. Not the entire line itself
– GreNIX
15 hours ago
Are you using an Operating System whose grep supports the-o
flag? (GNU/Linux systems, mainly)
– Jeff Schaller
15 hours ago
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
15 hours ago
Sorry, -o man page isn't confusing; -w is.
– GreNIX
15 hours ago
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 15 hours ago
GreNIX GreNIX
577
577
from a file, or from a command? Just that textdataset record count (etc)
or only the matching (entire) lines?
– Jeff Schaller
15 hours ago
Just that portion of the log file line. Not the entire line itself
– GreNIX
15 hours ago
Are you using an Operating System whose grep supports the-o
flag? (GNU/Linux systems, mainly)
– Jeff Schaller
15 hours ago
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
15 hours ago
Sorry, -o man page isn't confusing; -w is.
– GreNIX
15 hours ago
add a comment |
from a file, or from a command? Just that textdataset record count (etc)
or only the matching (entire) lines?
– Jeff Schaller
15 hours ago
Just that portion of the log file line. Not the entire line itself
– GreNIX
15 hours ago
Are you using an Operating System whose grep supports the-o
flag? (GNU/Linux systems, mainly)
– Jeff Schaller
15 hours ago
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
15 hours ago
Sorry, -o man page isn't confusing; -w is.
– GreNIX
15 hours ago
from a file, or from a command? Just that text
dataset record count (etc)
or only the matching (entire) lines?– Jeff Schaller
15 hours ago
from a file, or from a command? Just that text
dataset record count (etc)
or only the matching (entire) lines?– Jeff Schaller
15 hours ago
Just that portion of the log file line. Not the entire line itself
– GreNIX
15 hours ago
Just that portion of the log file line. Not the entire line itself
– GreNIX
15 hours ago
Are you using an Operating System whose grep supports the
-o
flag? (GNU/Linux systems, mainly)– Jeff Schaller
15 hours ago
Are you using an Operating System whose grep supports the
-o
flag? (GNU/Linux systems, mainly)– Jeff Schaller
15 hours ago
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
15 hours ago
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
15 hours ago
Sorry, -o man page isn't confusing; -w is.
– GreNIX
15 hours ago
Sorry, -o man page isn't confusing; -w is.
– GreNIX
15 hours ago
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
14 hours ago
I needed to add the + to the end of the bracket
– GreNIX
14 hours ago
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
14 hours ago
I needed to add the + to the end of the bracket
– GreNIX
14 hours ago
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
14 hours ago
I needed to add the + to the end of the bracket
– GreNIX
14 hours ago
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 15 hours ago
Jeff SchallerJeff Schaller
39.5k1054126
39.5k1054126
I've triedgrep -Eo 'dataset [a-z A-Z 0-9]'
but I'm not sure why it isn't working.
– GreNIX
14 hours ago
I needed to add the + to the end of the bracket
– GreNIX
14 hours ago
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
14 hours ago
I needed to add the + to the end of the bracket
– GreNIX
14 hours ago
I've tried
grep -Eo 'dataset [a-z A-Z 0-9]'
but I'm not sure why it isn't working.– GreNIX
14 hours ago
I've tried
grep -Eo 'dataset [a-z A-Z 0-9]'
but I'm not sure why it isn't working.– GreNIX
14 hours ago
I needed to add the + to the end of the bracket
– GreNIX
14 hours ago
I needed to add the + to the end of the bracket
– GreNIX
14 hours ago
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
15 hours ago
Just that portion of the log file line. Not the entire line itself
– GreNIX
15 hours ago
Are you using an Operating System whose grep supports the
-o
flag? (GNU/Linux systems, mainly)– Jeff Schaller
15 hours ago
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
15 hours ago
Sorry, -o man page isn't confusing; -w is.
– GreNIX
15 hours ago