grep or other regexp to get value of output
up vote
0
down vote
favorite
How to use grep
or any other tool to get a specific value in an output
In the below output I need to get the value 255.00
in the line with Minimum: 255.00 (1.0000)
A pattern like: Channel Statistics:s+Gray:s+Minimum: +([d.]+)
Image: test.tif
Format: TIFF (Tagged Image File Format)
Geometry: 2525x1785
Class: DirectClass
Type: bilevel
Depth: 1 bits-per-pixel component
Channel Depths:
Gray: 1 bits
Channel Statistics:
Gray:
Minimum: 255.00 (1.0000)
Maximum: 255.00 (1.0000)
Mean: 255.00 (1.0000)
Standard Deviation: 0.00 (0.0000)
Filesize: 581
Interlace: No
Orientation: Unknown
Background Color: white
Border Color: #DFDFDF
Matte Color: #BDBDBD
linux debian regex grep
add a comment |
up vote
0
down vote
favorite
How to use grep
or any other tool to get a specific value in an output
In the below output I need to get the value 255.00
in the line with Minimum: 255.00 (1.0000)
A pattern like: Channel Statistics:s+Gray:s+Minimum: +([d.]+)
Image: test.tif
Format: TIFF (Tagged Image File Format)
Geometry: 2525x1785
Class: DirectClass
Type: bilevel
Depth: 1 bits-per-pixel component
Channel Depths:
Gray: 1 bits
Channel Statistics:
Gray:
Minimum: 255.00 (1.0000)
Maximum: 255.00 (1.0000)
Mean: 255.00 (1.0000)
Standard Deviation: 0.00 (0.0000)
Filesize: 581
Interlace: No
Orientation: Unknown
Background Color: white
Border Color: #DFDFDF
Matte Color: #BDBDBD
linux debian regex grep
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
How to use grep
or any other tool to get a specific value in an output
In the below output I need to get the value 255.00
in the line with Minimum: 255.00 (1.0000)
A pattern like: Channel Statistics:s+Gray:s+Minimum: +([d.]+)
Image: test.tif
Format: TIFF (Tagged Image File Format)
Geometry: 2525x1785
Class: DirectClass
Type: bilevel
Depth: 1 bits-per-pixel component
Channel Depths:
Gray: 1 bits
Channel Statistics:
Gray:
Minimum: 255.00 (1.0000)
Maximum: 255.00 (1.0000)
Mean: 255.00 (1.0000)
Standard Deviation: 0.00 (0.0000)
Filesize: 581
Interlace: No
Orientation: Unknown
Background Color: white
Border Color: #DFDFDF
Matte Color: #BDBDBD
linux debian regex grep
How to use grep
or any other tool to get a specific value in an output
In the below output I need to get the value 255.00
in the line with Minimum: 255.00 (1.0000)
A pattern like: Channel Statistics:s+Gray:s+Minimum: +([d.]+)
Image: test.tif
Format: TIFF (Tagged Image File Format)
Geometry: 2525x1785
Class: DirectClass
Type: bilevel
Depth: 1 bits-per-pixel component
Channel Depths:
Gray: 1 bits
Channel Statistics:
Gray:
Minimum: 255.00 (1.0000)
Maximum: 255.00 (1.0000)
Mean: 255.00 (1.0000)
Standard Deviation: 0.00 (0.0000)
Filesize: 581
Interlace: No
Orientation: Unknown
Background Color: white
Border Color: #DFDFDF
Matte Color: #BDBDBD
linux debian regex grep
linux debian regex grep
asked Dec 1 at 11:24
clarkk
941313
941313
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
Using perl, you can do the following. It captures the numeric value after minimum:
inside the block Channel Statistics:
and prints it:
perl -0 -ne '/Channel Statistics:s+Gray:s+Minimum:h+([d.]+)/ && print $1,"n"' file
Output: (for given example)
255.00
Explanation:
-0 # specifies the input record separator. If there are no digits, the null character is the separator. The whole file is read in a single string.
-n # Iterate over the file
-e # execute the command line
Regex:
/ # regex delimiter
Channel Statistics: # literally
s+ # 1 or more any kind of spaces
Gray: # literally
s+ # 1 or more any kind of spaces
Minimum: # literally
h+ # 1 or more horizontal spaces
( # start group 1
[d.]+ # 1 or more digit or dot
) # end group
/ # regex delimiter
add a comment |
up vote
0
down vote
With sed
sed -rn 's/^s+Minimum:s+([0-9.]+).+$/1/p' image.data
In slow-mo:
-r
tellssed
we use th extened regexp "syntax"
-n
tellssed
to not print non-matching lines
s/^s+Minimum:s+([0-9.]+).+$/1/
matches your target line and replaces it with just the value you are after
p
tellssed
to print the result
If you need to disambiguate by taking in account the content of previous lines, it is just slightly more complicated:
sed -r ':a;N;$!ba; s/^.*Gray:s*ns+Minimum:s+([0-9.]+).+$/1/' image.data
where:
:a;N;$!ba;
is a loop in thesed
language that loads the whole file at once
-n
is no longer necessary since there are no other lines we don't want to print- the final
p
is no longer necessary either since we don't use-n
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Using perl, you can do the following. It captures the numeric value after minimum:
inside the block Channel Statistics:
and prints it:
perl -0 -ne '/Channel Statistics:s+Gray:s+Minimum:h+([d.]+)/ && print $1,"n"' file
Output: (for given example)
255.00
Explanation:
-0 # specifies the input record separator. If there are no digits, the null character is the separator. The whole file is read in a single string.
-n # Iterate over the file
-e # execute the command line
Regex:
/ # regex delimiter
Channel Statistics: # literally
s+ # 1 or more any kind of spaces
Gray: # literally
s+ # 1 or more any kind of spaces
Minimum: # literally
h+ # 1 or more horizontal spaces
( # start group 1
[d.]+ # 1 or more digit or dot
) # end group
/ # regex delimiter
add a comment |
up vote
0
down vote
Using perl, you can do the following. It captures the numeric value after minimum:
inside the block Channel Statistics:
and prints it:
perl -0 -ne '/Channel Statistics:s+Gray:s+Minimum:h+([d.]+)/ && print $1,"n"' file
Output: (for given example)
255.00
Explanation:
-0 # specifies the input record separator. If there are no digits, the null character is the separator. The whole file is read in a single string.
-n # Iterate over the file
-e # execute the command line
Regex:
/ # regex delimiter
Channel Statistics: # literally
s+ # 1 or more any kind of spaces
Gray: # literally
s+ # 1 or more any kind of spaces
Minimum: # literally
h+ # 1 or more horizontal spaces
( # start group 1
[d.]+ # 1 or more digit or dot
) # end group
/ # regex delimiter
add a comment |
up vote
0
down vote
up vote
0
down vote
Using perl, you can do the following. It captures the numeric value after minimum:
inside the block Channel Statistics:
and prints it:
perl -0 -ne '/Channel Statistics:s+Gray:s+Minimum:h+([d.]+)/ && print $1,"n"' file
Output: (for given example)
255.00
Explanation:
-0 # specifies the input record separator. If there are no digits, the null character is the separator. The whole file is read in a single string.
-n # Iterate over the file
-e # execute the command line
Regex:
/ # regex delimiter
Channel Statistics: # literally
s+ # 1 or more any kind of spaces
Gray: # literally
s+ # 1 or more any kind of spaces
Minimum: # literally
h+ # 1 or more horizontal spaces
( # start group 1
[d.]+ # 1 or more digit or dot
) # end group
/ # regex delimiter
Using perl, you can do the following. It captures the numeric value after minimum:
inside the block Channel Statistics:
and prints it:
perl -0 -ne '/Channel Statistics:s+Gray:s+Minimum:h+([d.]+)/ && print $1,"n"' file
Output: (for given example)
255.00
Explanation:
-0 # specifies the input record separator. If there are no digits, the null character is the separator. The whole file is read in a single string.
-n # Iterate over the file
-e # execute the command line
Regex:
/ # regex delimiter
Channel Statistics: # literally
s+ # 1 or more any kind of spaces
Gray: # literally
s+ # 1 or more any kind of spaces
Minimum: # literally
h+ # 1 or more horizontal spaces
( # start group 1
[d.]+ # 1 or more digit or dot
) # end group
/ # regex delimiter
answered Dec 1 at 13:11
Toto
3,38691126
3,38691126
add a comment |
add a comment |
up vote
0
down vote
With sed
sed -rn 's/^s+Minimum:s+([0-9.]+).+$/1/p' image.data
In slow-mo:
-r
tellssed
we use th extened regexp "syntax"
-n
tellssed
to not print non-matching lines
s/^s+Minimum:s+([0-9.]+).+$/1/
matches your target line and replaces it with just the value you are after
p
tellssed
to print the result
If you need to disambiguate by taking in account the content of previous lines, it is just slightly more complicated:
sed -r ':a;N;$!ba; s/^.*Gray:s*ns+Minimum:s+([0-9.]+).+$/1/' image.data
where:
:a;N;$!ba;
is a loop in thesed
language that loads the whole file at once
-n
is no longer necessary since there are no other lines we don't want to print- the final
p
is no longer necessary either since we don't use-n
add a comment |
up vote
0
down vote
With sed
sed -rn 's/^s+Minimum:s+([0-9.]+).+$/1/p' image.data
In slow-mo:
-r
tellssed
we use th extened regexp "syntax"
-n
tellssed
to not print non-matching lines
s/^s+Minimum:s+([0-9.]+).+$/1/
matches your target line and replaces it with just the value you are after
p
tellssed
to print the result
If you need to disambiguate by taking in account the content of previous lines, it is just slightly more complicated:
sed -r ':a;N;$!ba; s/^.*Gray:s*ns+Minimum:s+([0-9.]+).+$/1/' image.data
where:
:a;N;$!ba;
is a loop in thesed
language that loads the whole file at once
-n
is no longer necessary since there are no other lines we don't want to print- the final
p
is no longer necessary either since we don't use-n
add a comment |
up vote
0
down vote
up vote
0
down vote
With sed
sed -rn 's/^s+Minimum:s+([0-9.]+).+$/1/p' image.data
In slow-mo:
-r
tellssed
we use th extened regexp "syntax"
-n
tellssed
to not print non-matching lines
s/^s+Minimum:s+([0-9.]+).+$/1/
matches your target line and replaces it with just the value you are after
p
tellssed
to print the result
If you need to disambiguate by taking in account the content of previous lines, it is just slightly more complicated:
sed -r ':a;N;$!ba; s/^.*Gray:s*ns+Minimum:s+([0-9.]+).+$/1/' image.data
where:
:a;N;$!ba;
is a loop in thesed
language that loads the whole file at once
-n
is no longer necessary since there are no other lines we don't want to print- the final
p
is no longer necessary either since we don't use-n
With sed
sed -rn 's/^s+Minimum:s+([0-9.]+).+$/1/p' image.data
In slow-mo:
-r
tellssed
we use th extened regexp "syntax"
-n
tellssed
to not print non-matching lines
s/^s+Minimum:s+([0-9.]+).+$/1/
matches your target line and replaces it with just the value you are after
p
tellssed
to print the result
If you need to disambiguate by taking in account the content of previous lines, it is just slightly more complicated:
sed -r ':a;N;$!ba; s/^.*Gray:s*ns+Minimum:s+([0-9.]+).+$/1/' image.data
where:
:a;N;$!ba;
is a loop in thesed
language that loads the whole file at once
-n
is no longer necessary since there are no other lines we don't want to print- the final
p
is no longer necessary either since we don't use-n
edited Dec 1 at 17:17
answered Dec 1 at 16:49
xenoid
3,5783718
3,5783718
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2fsuperuser.com%2fquestions%2f1379939%2fgrep-or-other-regexp-to-get-value-of-output%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