How to extract only values greater than a thresholdHow to find out common elements between two files?How to wrap the comma delimited values to the next line without disturbing the other fields using awk or kshHow to print incremental count of occurrences of unique values in column 1Extract datetime and values for gnuplotHow to extract unique values from column #x with its corresponding values of column# y?Lines per second scriptHow to change values of one column using other column's values from a different fileHow to remove lines from a text file that has specific value in a column through input file?Extract lines from a file with a value,whose parameter greater than 100, with grep and awkHow to grep a string with any two numbers that match or that have the first number one less than the second number?
Why does BezierFunction not follow BezierCurve at npts>4?
Why do player start with fighting for the corners in go?
Meaning of ギャップ in the following sentence
Is law enforcement responsible for damages made by a search warrant?
Does the problem of P vs NP come under the category of Operational Research?
How do I safety check that there is no light in Darkroom / Darkbag?
Phase portrait of a system of differential equations
C# TCP server/client class
How do people drown while wearing a life jacket?
What license to choose for my PhD thesis?
Astable 555 circuit not oscillating
How to win an all out war against ants
How were x-ray diffraction patterns deciphered before computers?
Reasons for using monsters as bioweapons
Gödel's paradox: Why is "a proof that some universal statement is unprovable" not a valid proof that this statement is true?
How to handle many times series?
Why have both: BJT and FET transistors on IC output?
How does Rust's 128-bit integer `i128` work on a 64-bit system?
How was the cosmonaut of the Soviet moon mission supposed to get back in the return vehicle?
Confused over role of 「自分が」in this particular passage
Why isn't the new LEGO CV joint available on Bricklink or Brickowl?
Search and replace a substring only if another substring is not present
Is the first page of Novel really that important?
How do I find version of Intel graphics card drivers installed?
How to extract only values greater than a threshold
How to find out common elements between two files?How to wrap the comma delimited values to the next line without disturbing the other fields using awk or kshHow to print incremental count of occurrences of unique values in column 1Extract datetime and values for gnuplotHow to extract unique values from column #x with its corresponding values of column# y?Lines per second scriptHow to change values of one column using other column's values from a different fileHow to remove lines from a text file that has specific value in a column through input file?Extract lines from a file with a value,whose parameter greater than 100, with grep and awkHow to grep a string with any two numbers that match or that have the first number one less than the second number?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am new to bash scripting. Could someone help me with the following?
I have a log file with output as shown below.
I'm trying to grep for lines of an output with logDurationMillis>=950ms
logAlias:Overall,logDurationMillis:382,logTimeStart:2019-07-24_15:30:06.075,logTimeStop:2019-07-24_15:30:06.107
logAlias:Overall,logDurationMillis:388,logTimeStart:2019-07-24_15:30:06.406,logTimeStop:2019-07-24_15:30:06.444
logAlias:Overall,logDurationMillis:545,logTimeStart:2019-07-24_15:30:06.583,logTimeStop:2019-07-24_15:30:06.638
logAlias:Overall,logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.599,logTimeStop:2019-07-24_15:30:06.660
logAlias:Overall,logDurationMillis:640,logTimeStart:2019-07-24_15:30:07.197,logTimeStop:2019-07-24_15:30:07.237
logAlias:Overall,logDurationMillis:934,logTimeStart:2019-07-24_15:30:07.474,logTimeStop:2019-07-24_15:30:07.508
logAlias:Overall,logDurationMillis:336,logTimeStart:2019-07-24_15:30:07.546,logTimeStop:2019-07-24_15:30:07.582
The values are always in the second comma-delimited column.
awk grep logs
add a comment |
I am new to bash scripting. Could someone help me with the following?
I have a log file with output as shown below.
I'm trying to grep for lines of an output with logDurationMillis>=950ms
logAlias:Overall,logDurationMillis:382,logTimeStart:2019-07-24_15:30:06.075,logTimeStop:2019-07-24_15:30:06.107
logAlias:Overall,logDurationMillis:388,logTimeStart:2019-07-24_15:30:06.406,logTimeStop:2019-07-24_15:30:06.444
logAlias:Overall,logDurationMillis:545,logTimeStart:2019-07-24_15:30:06.583,logTimeStop:2019-07-24_15:30:06.638
logAlias:Overall,logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.599,logTimeStop:2019-07-24_15:30:06.660
logAlias:Overall,logDurationMillis:640,logTimeStart:2019-07-24_15:30:07.197,logTimeStop:2019-07-24_15:30:07.237
logAlias:Overall,logDurationMillis:934,logTimeStart:2019-07-24_15:30:07.474,logTimeStop:2019-07-24_15:30:07.508
logAlias:Overall,logDurationMillis:336,logTimeStart:2019-07-24_15:30:07.546,logTimeStop:2019-07-24_15:30:07.582
The values are always in the second comma-delimited column.
awk grep logs
add a comment |
I am new to bash scripting. Could someone help me with the following?
I have a log file with output as shown below.
I'm trying to grep for lines of an output with logDurationMillis>=950ms
logAlias:Overall,logDurationMillis:382,logTimeStart:2019-07-24_15:30:06.075,logTimeStop:2019-07-24_15:30:06.107
logAlias:Overall,logDurationMillis:388,logTimeStart:2019-07-24_15:30:06.406,logTimeStop:2019-07-24_15:30:06.444
logAlias:Overall,logDurationMillis:545,logTimeStart:2019-07-24_15:30:06.583,logTimeStop:2019-07-24_15:30:06.638
logAlias:Overall,logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.599,logTimeStop:2019-07-24_15:30:06.660
logAlias:Overall,logDurationMillis:640,logTimeStart:2019-07-24_15:30:07.197,logTimeStop:2019-07-24_15:30:07.237
logAlias:Overall,logDurationMillis:934,logTimeStart:2019-07-24_15:30:07.474,logTimeStop:2019-07-24_15:30:07.508
logAlias:Overall,logDurationMillis:336,logTimeStart:2019-07-24_15:30:07.546,logTimeStop:2019-07-24_15:30:07.582
The values are always in the second comma-delimited column.
awk grep logs
I am new to bash scripting. Could someone help me with the following?
I have a log file with output as shown below.
I'm trying to grep for lines of an output with logDurationMillis>=950ms
logAlias:Overall,logDurationMillis:382,logTimeStart:2019-07-24_15:30:06.075,logTimeStop:2019-07-24_15:30:06.107
logAlias:Overall,logDurationMillis:388,logTimeStart:2019-07-24_15:30:06.406,logTimeStop:2019-07-24_15:30:06.444
logAlias:Overall,logDurationMillis:545,logTimeStart:2019-07-24_15:30:06.583,logTimeStop:2019-07-24_15:30:06.638
logAlias:Overall,logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.599,logTimeStop:2019-07-24_15:30:06.660
logAlias:Overall,logDurationMillis:640,logTimeStart:2019-07-24_15:30:07.197,logTimeStop:2019-07-24_15:30:07.237
logAlias:Overall,logDurationMillis:934,logTimeStart:2019-07-24_15:30:07.474,logTimeStop:2019-07-24_15:30:07.508
logAlias:Overall,logDurationMillis:336,logTimeStart:2019-07-24_15:30:07.546,logTimeStop:2019-07-24_15:30:07.582
The values are always in the second comma-delimited column.
awk grep logs
awk grep logs
edited Jul 24 at 20:07
Jeff Schaller♦
48.4k11 gold badges72 silver badges162 bronze badges
48.4k11 gold badges72 silver badges162 bronze badges
asked Jul 24 at 19:32
Aslam534Aslam534
273 bronze badges
273 bronze badges
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
With awk:
if you know "logDurationMillis" is the second item:
awk -F'[:,]' -v limit=950 '$4 >= limit' file
otherwise
awk -F'[:,]' -v limit=950 '
for (i=1; i<NF; i+=2)
if ($i == "logDurationMillis" && $(i+1) >= limit)
print
' file
2
I did not know you could do that with the delimiter! Awesome
– Jesse_b
Jul 24 at 19:42
logDurationMillis is the second field so i tried the 2nd script you have provided, It worked.. Thank you so much
– Aslam534
Jul 24 at 19:52
@Jesse_b: awk (even regular awk) can accept regexps as delimiter, and also extended ones (ex:-F 'this|that[ _]*also'
will separate fields with "this" and with "thatalso" or "that also" or "that_also" (and allow even multiple occurences of space or _, as there is a '*' in the regexp). It can be really handy. Here, in this answer, it separates fields with either 1 "," or 1 ":", so it will separate fields at each occurence of "," or ":" . (if the line starts with a separator, $1 is empty and $2 is the next field)
– Olivier Dulac
Jul 25 at 18:05
@glennjackman: Could you please edit that first one? to put $4 as you clearly intended to. (I am not sure if it is correct etiquette to edit it myself as it "changes" the answer...)
– Olivier Dulac
Jul 25 at 18:09
I did update it. It would be absolutely appropriate for you to edit my answer. The OP changed the input data after I answered, and a simple change like that does not alter the intent of the answer.
– glenn jackman
Jul 25 at 19:44
add a comment |
Assuming your file is named logFile
, this command will do it:
egrep ',logDurationMillis:(9[5-9][0-9]|[1-9][0-9]3,),' logFile
Using a regexp for a numeric comparison results in hard to understand/maintain code. To compare numbers, just use awk with a numeric comparison - there's zero reason to do this with regexps in grep.
– Ed Morton
Jul 25 at 17:12
add a comment |
another awk
one:
awk -F':|,' '$4 > 950' file
prints:
logAlias:Overall,logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.599,logTimeStop:2019-07-24_15:30:06.660
Update (due to OPs Question:)
you can reconstruct the fields like this:
awk -F':|,' '$4 > 950 print $3 ":" $4 "," $5 ":" $6 ":" $7 ":" $8 ' file
prints:
logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.599
(there is probably a simpler way that concatinates the fields 3-8, but you also need to reconstruct the different field separators)
1
(1) This is basically the same as glenn jackman’s answer. (2) The question says “>=950”, but your answer says> 950
.
– G-Man
Jul 25 at 2:58
2
That double pipe||
looks odd. The intervening part would match the empty string too, but what use is that? Why not just:|,
?
– ilkkachu
Jul 25 at 7:10
1
@ilkkachu: Good catch; I missed that. I suspect that nath meant:|,
— as I said, equivalent to glenn’s[:,]
— but reflexively typed||
for “OR”. But, AFAICT in six to eight minutes of testing, this answer works. Can you demonstrate that the extra|
actually causes it to fail?
– G-Man
Jul 25 at 13:24
1
@G-Man a|
immediately following|
is undefined behavior per POSIX, see pubs.opengroup.org/onlinepubs/9699919799/basedefs/…:| ... A <vertical-line> appearing ... immediately following a <vertical-line> ... produces undefined results.
. So that code could do anything in any given awk.
– Ed Morton
Jul 25 at 17:16
Thanks Nath, 'awk -F':||,' '$4 > 950' file' works :) Actual log file is like logAlias:Overall,logDurationMillis:382,logTimeStart:2019-07-24_15:30:06.075,logTimeStop:2019-07-24_15:30:06.107, UniqueId.... question :How do i get only following fields in result logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.075,UniqueId
– Aslam534
Jul 26 at 6:35
|
show 3 more comments
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%2f531947%2fhow-to-extract-only-values-greater-than-a-threshold%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
With awk:
if you know "logDurationMillis" is the second item:
awk -F'[:,]' -v limit=950 '$4 >= limit' file
otherwise
awk -F'[:,]' -v limit=950 '
for (i=1; i<NF; i+=2)
if ($i == "logDurationMillis" && $(i+1) >= limit)
print
' file
2
I did not know you could do that with the delimiter! Awesome
– Jesse_b
Jul 24 at 19:42
logDurationMillis is the second field so i tried the 2nd script you have provided, It worked.. Thank you so much
– Aslam534
Jul 24 at 19:52
@Jesse_b: awk (even regular awk) can accept regexps as delimiter, and also extended ones (ex:-F 'this|that[ _]*also'
will separate fields with "this" and with "thatalso" or "that also" or "that_also" (and allow even multiple occurences of space or _, as there is a '*' in the regexp). It can be really handy. Here, in this answer, it separates fields with either 1 "," or 1 ":", so it will separate fields at each occurence of "," or ":" . (if the line starts with a separator, $1 is empty and $2 is the next field)
– Olivier Dulac
Jul 25 at 18:05
@glennjackman: Could you please edit that first one? to put $4 as you clearly intended to. (I am not sure if it is correct etiquette to edit it myself as it "changes" the answer...)
– Olivier Dulac
Jul 25 at 18:09
I did update it. It would be absolutely appropriate for you to edit my answer. The OP changed the input data after I answered, and a simple change like that does not alter the intent of the answer.
– glenn jackman
Jul 25 at 19:44
add a comment |
With awk:
if you know "logDurationMillis" is the second item:
awk -F'[:,]' -v limit=950 '$4 >= limit' file
otherwise
awk -F'[:,]' -v limit=950 '
for (i=1; i<NF; i+=2)
if ($i == "logDurationMillis" && $(i+1) >= limit)
print
' file
2
I did not know you could do that with the delimiter! Awesome
– Jesse_b
Jul 24 at 19:42
logDurationMillis is the second field so i tried the 2nd script you have provided, It worked.. Thank you so much
– Aslam534
Jul 24 at 19:52
@Jesse_b: awk (even regular awk) can accept regexps as delimiter, and also extended ones (ex:-F 'this|that[ _]*also'
will separate fields with "this" and with "thatalso" or "that also" or "that_also" (and allow even multiple occurences of space or _, as there is a '*' in the regexp). It can be really handy. Here, in this answer, it separates fields with either 1 "," or 1 ":", so it will separate fields at each occurence of "," or ":" . (if the line starts with a separator, $1 is empty and $2 is the next field)
– Olivier Dulac
Jul 25 at 18:05
@glennjackman: Could you please edit that first one? to put $4 as you clearly intended to. (I am not sure if it is correct etiquette to edit it myself as it "changes" the answer...)
– Olivier Dulac
Jul 25 at 18:09
I did update it. It would be absolutely appropriate for you to edit my answer. The OP changed the input data after I answered, and a simple change like that does not alter the intent of the answer.
– glenn jackman
Jul 25 at 19:44
add a comment |
With awk:
if you know "logDurationMillis" is the second item:
awk -F'[:,]' -v limit=950 '$4 >= limit' file
otherwise
awk -F'[:,]' -v limit=950 '
for (i=1; i<NF; i+=2)
if ($i == "logDurationMillis" && $(i+1) >= limit)
print
' file
With awk:
if you know "logDurationMillis" is the second item:
awk -F'[:,]' -v limit=950 '$4 >= limit' file
otherwise
awk -F'[:,]' -v limit=950 '
for (i=1; i<NF; i+=2)
if ($i == "logDurationMillis" && $(i+1) >= limit)
print
' file
edited Jul 25 at 19:42
answered Jul 24 at 19:41
glenn jackmanglenn jackman
55.9k6 gold badges77 silver badges117 bronze badges
55.9k6 gold badges77 silver badges117 bronze badges
2
I did not know you could do that with the delimiter! Awesome
– Jesse_b
Jul 24 at 19:42
logDurationMillis is the second field so i tried the 2nd script you have provided, It worked.. Thank you so much
– Aslam534
Jul 24 at 19:52
@Jesse_b: awk (even regular awk) can accept regexps as delimiter, and also extended ones (ex:-F 'this|that[ _]*also'
will separate fields with "this" and with "thatalso" or "that also" or "that_also" (and allow even multiple occurences of space or _, as there is a '*' in the regexp). It can be really handy. Here, in this answer, it separates fields with either 1 "," or 1 ":", so it will separate fields at each occurence of "," or ":" . (if the line starts with a separator, $1 is empty and $2 is the next field)
– Olivier Dulac
Jul 25 at 18:05
@glennjackman: Could you please edit that first one? to put $4 as you clearly intended to. (I am not sure if it is correct etiquette to edit it myself as it "changes" the answer...)
– Olivier Dulac
Jul 25 at 18:09
I did update it. It would be absolutely appropriate for you to edit my answer. The OP changed the input data after I answered, and a simple change like that does not alter the intent of the answer.
– glenn jackman
Jul 25 at 19:44
add a comment |
2
I did not know you could do that with the delimiter! Awesome
– Jesse_b
Jul 24 at 19:42
logDurationMillis is the second field so i tried the 2nd script you have provided, It worked.. Thank you so much
– Aslam534
Jul 24 at 19:52
@Jesse_b: awk (even regular awk) can accept regexps as delimiter, and also extended ones (ex:-F 'this|that[ _]*also'
will separate fields with "this" and with "thatalso" or "that also" or "that_also" (and allow even multiple occurences of space or _, as there is a '*' in the regexp). It can be really handy. Here, in this answer, it separates fields with either 1 "," or 1 ":", so it will separate fields at each occurence of "," or ":" . (if the line starts with a separator, $1 is empty and $2 is the next field)
– Olivier Dulac
Jul 25 at 18:05
@glennjackman: Could you please edit that first one? to put $4 as you clearly intended to. (I am not sure if it is correct etiquette to edit it myself as it "changes" the answer...)
– Olivier Dulac
Jul 25 at 18:09
I did update it. It would be absolutely appropriate for you to edit my answer. The OP changed the input data after I answered, and a simple change like that does not alter the intent of the answer.
– glenn jackman
Jul 25 at 19:44
2
2
I did not know you could do that with the delimiter! Awesome
– Jesse_b
Jul 24 at 19:42
I did not know you could do that with the delimiter! Awesome
– Jesse_b
Jul 24 at 19:42
logDurationMillis is the second field so i tried the 2nd script you have provided, It worked.. Thank you so much
– Aslam534
Jul 24 at 19:52
logDurationMillis is the second field so i tried the 2nd script you have provided, It worked.. Thank you so much
– Aslam534
Jul 24 at 19:52
@Jesse_b: awk (even regular awk) can accept regexps as delimiter, and also extended ones (ex:
-F 'this|that[ _]*also'
will separate fields with "this" and with "thatalso" or "that also" or "that_also" (and allow even multiple occurences of space or _, as there is a '*' in the regexp). It can be really handy. Here, in this answer, it separates fields with either 1 "," or 1 ":", so it will separate fields at each occurence of "," or ":" . (if the line starts with a separator, $1 is empty and $2 is the next field)– Olivier Dulac
Jul 25 at 18:05
@Jesse_b: awk (even regular awk) can accept regexps as delimiter, and also extended ones (ex:
-F 'this|that[ _]*also'
will separate fields with "this" and with "thatalso" or "that also" or "that_also" (and allow even multiple occurences of space or _, as there is a '*' in the regexp). It can be really handy. Here, in this answer, it separates fields with either 1 "," or 1 ":", so it will separate fields at each occurence of "," or ":" . (if the line starts with a separator, $1 is empty and $2 is the next field)– Olivier Dulac
Jul 25 at 18:05
@glennjackman: Could you please edit that first one? to put $4 as you clearly intended to. (I am not sure if it is correct etiquette to edit it myself as it "changes" the answer...)
– Olivier Dulac
Jul 25 at 18:09
@glennjackman: Could you please edit that first one? to put $4 as you clearly intended to. (I am not sure if it is correct etiquette to edit it myself as it "changes" the answer...)
– Olivier Dulac
Jul 25 at 18:09
I did update it. It would be absolutely appropriate for you to edit my answer. The OP changed the input data after I answered, and a simple change like that does not alter the intent of the answer.
– glenn jackman
Jul 25 at 19:44
I did update it. It would be absolutely appropriate for you to edit my answer. The OP changed the input data after I answered, and a simple change like that does not alter the intent of the answer.
– glenn jackman
Jul 25 at 19:44
add a comment |
Assuming your file is named logFile
, this command will do it:
egrep ',logDurationMillis:(9[5-9][0-9]|[1-9][0-9]3,),' logFile
Using a regexp for a numeric comparison results in hard to understand/maintain code. To compare numbers, just use awk with a numeric comparison - there's zero reason to do this with regexps in grep.
– Ed Morton
Jul 25 at 17:12
add a comment |
Assuming your file is named logFile
, this command will do it:
egrep ',logDurationMillis:(9[5-9][0-9]|[1-9][0-9]3,),' logFile
Using a regexp for a numeric comparison results in hard to understand/maintain code. To compare numbers, just use awk with a numeric comparison - there's zero reason to do this with regexps in grep.
– Ed Morton
Jul 25 at 17:12
add a comment |
Assuming your file is named logFile
, this command will do it:
egrep ',logDurationMillis:(9[5-9][0-9]|[1-9][0-9]3,),' logFile
Assuming your file is named logFile
, this command will do it:
egrep ',logDurationMillis:(9[5-9][0-9]|[1-9][0-9]3,),' logFile
edited Jul 24 at 22:42
answered Jul 24 at 19:37
Jim L.Jim L.
1,3543 silver badges6 bronze badges
1,3543 silver badges6 bronze badges
Using a regexp for a numeric comparison results in hard to understand/maintain code. To compare numbers, just use awk with a numeric comparison - there's zero reason to do this with regexps in grep.
– Ed Morton
Jul 25 at 17:12
add a comment |
Using a regexp for a numeric comparison results in hard to understand/maintain code. To compare numbers, just use awk with a numeric comparison - there's zero reason to do this with regexps in grep.
– Ed Morton
Jul 25 at 17:12
Using a regexp for a numeric comparison results in hard to understand/maintain code. To compare numbers, just use awk with a numeric comparison - there's zero reason to do this with regexps in grep.
– Ed Morton
Jul 25 at 17:12
Using a regexp for a numeric comparison results in hard to understand/maintain code. To compare numbers, just use awk with a numeric comparison - there's zero reason to do this with regexps in grep.
– Ed Morton
Jul 25 at 17:12
add a comment |
another awk
one:
awk -F':|,' '$4 > 950' file
prints:
logAlias:Overall,logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.599,logTimeStop:2019-07-24_15:30:06.660
Update (due to OPs Question:)
you can reconstruct the fields like this:
awk -F':|,' '$4 > 950 print $3 ":" $4 "," $5 ":" $6 ":" $7 ":" $8 ' file
prints:
logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.599
(there is probably a simpler way that concatinates the fields 3-8, but you also need to reconstruct the different field separators)
1
(1) This is basically the same as glenn jackman’s answer. (2) The question says “>=950”, but your answer says> 950
.
– G-Man
Jul 25 at 2:58
2
That double pipe||
looks odd. The intervening part would match the empty string too, but what use is that? Why not just:|,
?
– ilkkachu
Jul 25 at 7:10
1
@ilkkachu: Good catch; I missed that. I suspect that nath meant:|,
— as I said, equivalent to glenn’s[:,]
— but reflexively typed||
for “OR”. But, AFAICT in six to eight minutes of testing, this answer works. Can you demonstrate that the extra|
actually causes it to fail?
– G-Man
Jul 25 at 13:24
1
@G-Man a|
immediately following|
is undefined behavior per POSIX, see pubs.opengroup.org/onlinepubs/9699919799/basedefs/…:| ... A <vertical-line> appearing ... immediately following a <vertical-line> ... produces undefined results.
. So that code could do anything in any given awk.
– Ed Morton
Jul 25 at 17:16
Thanks Nath, 'awk -F':||,' '$4 > 950' file' works :) Actual log file is like logAlias:Overall,logDurationMillis:382,logTimeStart:2019-07-24_15:30:06.075,logTimeStop:2019-07-24_15:30:06.107, UniqueId.... question :How do i get only following fields in result logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.075,UniqueId
– Aslam534
Jul 26 at 6:35
|
show 3 more comments
another awk
one:
awk -F':|,' '$4 > 950' file
prints:
logAlias:Overall,logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.599,logTimeStop:2019-07-24_15:30:06.660
Update (due to OPs Question:)
you can reconstruct the fields like this:
awk -F':|,' '$4 > 950 print $3 ":" $4 "," $5 ":" $6 ":" $7 ":" $8 ' file
prints:
logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.599
(there is probably a simpler way that concatinates the fields 3-8, but you also need to reconstruct the different field separators)
1
(1) This is basically the same as glenn jackman’s answer. (2) The question says “>=950”, but your answer says> 950
.
– G-Man
Jul 25 at 2:58
2
That double pipe||
looks odd. The intervening part would match the empty string too, but what use is that? Why not just:|,
?
– ilkkachu
Jul 25 at 7:10
1
@ilkkachu: Good catch; I missed that. I suspect that nath meant:|,
— as I said, equivalent to glenn’s[:,]
— but reflexively typed||
for “OR”. But, AFAICT in six to eight minutes of testing, this answer works. Can you demonstrate that the extra|
actually causes it to fail?
– G-Man
Jul 25 at 13:24
1
@G-Man a|
immediately following|
is undefined behavior per POSIX, see pubs.opengroup.org/onlinepubs/9699919799/basedefs/…:| ... A <vertical-line> appearing ... immediately following a <vertical-line> ... produces undefined results.
. So that code could do anything in any given awk.
– Ed Morton
Jul 25 at 17:16
Thanks Nath, 'awk -F':||,' '$4 > 950' file' works :) Actual log file is like logAlias:Overall,logDurationMillis:382,logTimeStart:2019-07-24_15:30:06.075,logTimeStop:2019-07-24_15:30:06.107, UniqueId.... question :How do i get only following fields in result logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.075,UniqueId
– Aslam534
Jul 26 at 6:35
|
show 3 more comments
another awk
one:
awk -F':|,' '$4 > 950' file
prints:
logAlias:Overall,logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.599,logTimeStop:2019-07-24_15:30:06.660
Update (due to OPs Question:)
you can reconstruct the fields like this:
awk -F':|,' '$4 > 950 print $3 ":" $4 "," $5 ":" $6 ":" $7 ":" $8 ' file
prints:
logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.599
(there is probably a simpler way that concatinates the fields 3-8, but you also need to reconstruct the different field separators)
another awk
one:
awk -F':|,' '$4 > 950' file
prints:
logAlias:Overall,logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.599,logTimeStop:2019-07-24_15:30:06.660
Update (due to OPs Question:)
you can reconstruct the fields like this:
awk -F':|,' '$4 > 950 print $3 ":" $4 "," $5 ":" $6 ":" $7 ":" $8 ' file
prints:
logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.599
(there is probably a simpler way that concatinates the fields 3-8, but you also need to reconstruct the different field separators)
edited Jul 26 at 22:24
answered Jul 24 at 21:03
nathnath
1,20812 silver badges36 bronze badges
1,20812 silver badges36 bronze badges
1
(1) This is basically the same as glenn jackman’s answer. (2) The question says “>=950”, but your answer says> 950
.
– G-Man
Jul 25 at 2:58
2
That double pipe||
looks odd. The intervening part would match the empty string too, but what use is that? Why not just:|,
?
– ilkkachu
Jul 25 at 7:10
1
@ilkkachu: Good catch; I missed that. I suspect that nath meant:|,
— as I said, equivalent to glenn’s[:,]
— but reflexively typed||
for “OR”. But, AFAICT in six to eight minutes of testing, this answer works. Can you demonstrate that the extra|
actually causes it to fail?
– G-Man
Jul 25 at 13:24
1
@G-Man a|
immediately following|
is undefined behavior per POSIX, see pubs.opengroup.org/onlinepubs/9699919799/basedefs/…:| ... A <vertical-line> appearing ... immediately following a <vertical-line> ... produces undefined results.
. So that code could do anything in any given awk.
– Ed Morton
Jul 25 at 17:16
Thanks Nath, 'awk -F':||,' '$4 > 950' file' works :) Actual log file is like logAlias:Overall,logDurationMillis:382,logTimeStart:2019-07-24_15:30:06.075,logTimeStop:2019-07-24_15:30:06.107, UniqueId.... question :How do i get only following fields in result logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.075,UniqueId
– Aslam534
Jul 26 at 6:35
|
show 3 more comments
1
(1) This is basically the same as glenn jackman’s answer. (2) The question says “>=950”, but your answer says> 950
.
– G-Man
Jul 25 at 2:58
2
That double pipe||
looks odd. The intervening part would match the empty string too, but what use is that? Why not just:|,
?
– ilkkachu
Jul 25 at 7:10
1
@ilkkachu: Good catch; I missed that. I suspect that nath meant:|,
— as I said, equivalent to glenn’s[:,]
— but reflexively typed||
for “OR”. But, AFAICT in six to eight minutes of testing, this answer works. Can you demonstrate that the extra|
actually causes it to fail?
– G-Man
Jul 25 at 13:24
1
@G-Man a|
immediately following|
is undefined behavior per POSIX, see pubs.opengroup.org/onlinepubs/9699919799/basedefs/…:| ... A <vertical-line> appearing ... immediately following a <vertical-line> ... produces undefined results.
. So that code could do anything in any given awk.
– Ed Morton
Jul 25 at 17:16
Thanks Nath, 'awk -F':||,' '$4 > 950' file' works :) Actual log file is like logAlias:Overall,logDurationMillis:382,logTimeStart:2019-07-24_15:30:06.075,logTimeStop:2019-07-24_15:30:06.107, UniqueId.... question :How do i get only following fields in result logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.075,UniqueId
– Aslam534
Jul 26 at 6:35
1
1
(1) This is basically the same as glenn jackman’s answer. (2) The question says “>=950”, but your answer says
> 950
.– G-Man
Jul 25 at 2:58
(1) This is basically the same as glenn jackman’s answer. (2) The question says “>=950”, but your answer says
> 950
.– G-Man
Jul 25 at 2:58
2
2
That double pipe
||
looks odd. The intervening part would match the empty string too, but what use is that? Why not just :|,
?– ilkkachu
Jul 25 at 7:10
That double pipe
||
looks odd. The intervening part would match the empty string too, but what use is that? Why not just :|,
?– ilkkachu
Jul 25 at 7:10
1
1
@ilkkachu: Good catch; I missed that. I suspect that nath meant
:|,
— as I said, equivalent to glenn’s [:,]
— but reflexively typed ||
for “OR”. But, AFAICT in six to eight minutes of testing, this answer works. Can you demonstrate that the extra |
actually causes it to fail?– G-Man
Jul 25 at 13:24
@ilkkachu: Good catch; I missed that. I suspect that nath meant
:|,
— as I said, equivalent to glenn’s [:,]
— but reflexively typed ||
for “OR”. But, AFAICT in six to eight minutes of testing, this answer works. Can you demonstrate that the extra |
actually causes it to fail?– G-Man
Jul 25 at 13:24
1
1
@G-Man a
|
immediately following |
is undefined behavior per POSIX, see pubs.opengroup.org/onlinepubs/9699919799/basedefs/…: | ... A <vertical-line> appearing ... immediately following a <vertical-line> ... produces undefined results.
. So that code could do anything in any given awk.– Ed Morton
Jul 25 at 17:16
@G-Man a
|
immediately following |
is undefined behavior per POSIX, see pubs.opengroup.org/onlinepubs/9699919799/basedefs/…: | ... A <vertical-line> appearing ... immediately following a <vertical-line> ... produces undefined results.
. So that code could do anything in any given awk.– Ed Morton
Jul 25 at 17:16
Thanks Nath, 'awk -F':||,' '$4 > 950' file' works :) Actual log file is like logAlias:Overall,logDurationMillis:382,logTimeStart:2019-07-24_15:30:06.075,logTimeStop:2019-07-24_15:30:06.107, UniqueId.... question :How do i get only following fields in result logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.075,UniqueId
– Aslam534
Jul 26 at 6:35
Thanks Nath, 'awk -F':||,' '$4 > 950' file' works :) Actual log file is like logAlias:Overall,logDurationMillis:382,logTimeStart:2019-07-24_15:30:06.075,logTimeStop:2019-07-24_15:30:06.107, UniqueId.... question :How do i get only following fields in result logDurationMillis:961,logTimeStart:2019-07-24_15:30:06.075,UniqueId
– Aslam534
Jul 26 at 6:35
|
show 3 more comments
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%2f531947%2fhow-to-extract-only-values-greater-than-a-threshold%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