Isolate portion of line from log file, then print to screen












0















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?










share|improve this question























  • 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
















0















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?










share|improve this question























  • 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














0












0








0








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 15 hours ago









GreNIX GreNIX

577




577













  • 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



















  • 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

















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










1 Answer
1






active

oldest

votes


















2














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:]]+'





share|improve this answer
























  • 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











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%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









2














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:]]+'





share|improve this answer
























  • 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
















2














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:]]+'





share|improve this answer
























  • 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














2












2








2







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:]]+'





share|improve this answer













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:]]+'






share|improve this answer












share|improve this answer



share|improve this answer










answered 15 hours ago









Jeff SchallerJeff Schaller

39.5k1054126




39.5k1054126













  • 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'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'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


















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%2f495115%2fisolate-portion-of-line-from-log-file-then-print-to-screen%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

Loup dans la culture

How to solve the problem of ntp “Unable to contact time server” from KDE?

ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux