How to extract word which has only numbers separated by 'dot'
up vote
0
down vote
favorite
From below lines
abcd efgh ijhk lmn opqrs 9.0.8.2c tuv wxyz
abcd efgh ijhk lmn opqrs 8.1.3.9b
How to extract only
9.0.8.2c
8.1.3.9b
linux text-processing pattern-matching
add a comment |
up vote
0
down vote
favorite
From below lines
abcd efgh ijhk lmn opqrs 9.0.8.2c tuv wxyz
abcd efgh ijhk lmn opqrs 8.1.3.9b
How to extract only
9.0.8.2c
8.1.3.9b
linux text-processing pattern-matching
It would be more helpful if your sample had more examples of things you don't want it to match (like what aboutfoo1.2
,foo-1.2
,1.2-3
). How do you define word? How do you define number?9c
being a number implies numbers here are hexadecimal numbers. Is that right?
– Stéphane Chazelas
Dec 6 at 9:10
Why isn'tabcd
to be matched? That's an hexadecimal number as well. Is that because you need those words to contain at least two numbers?
– Stéphane Chazelas
Dec 6 at 9:44
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
From below lines
abcd efgh ijhk lmn opqrs 9.0.8.2c tuv wxyz
abcd efgh ijhk lmn opqrs 8.1.3.9b
How to extract only
9.0.8.2c
8.1.3.9b
linux text-processing pattern-matching
From below lines
abcd efgh ijhk lmn opqrs 9.0.8.2c tuv wxyz
abcd efgh ijhk lmn opqrs 8.1.3.9b
How to extract only
9.0.8.2c
8.1.3.9b
linux text-processing pattern-matching
linux text-processing pattern-matching
edited Dec 6 at 11:18
Isaac
11k11648
11k11648
asked Dec 6 at 8:53
GSG
1
1
It would be more helpful if your sample had more examples of things you don't want it to match (like what aboutfoo1.2
,foo-1.2
,1.2-3
). How do you define word? How do you define number?9c
being a number implies numbers here are hexadecimal numbers. Is that right?
– Stéphane Chazelas
Dec 6 at 9:10
Why isn'tabcd
to be matched? That's an hexadecimal number as well. Is that because you need those words to contain at least two numbers?
– Stéphane Chazelas
Dec 6 at 9:44
add a comment |
It would be more helpful if your sample had more examples of things you don't want it to match (like what aboutfoo1.2
,foo-1.2
,1.2-3
). How do you define word? How do you define number?9c
being a number implies numbers here are hexadecimal numbers. Is that right?
– Stéphane Chazelas
Dec 6 at 9:10
Why isn'tabcd
to be matched? That's an hexadecimal number as well. Is that because you need those words to contain at least two numbers?
– Stéphane Chazelas
Dec 6 at 9:44
It would be more helpful if your sample had more examples of things you don't want it to match (like what about
foo1.2
, foo-1.2
, 1.2-3
). How do you define word? How do you define number? 9c
being a number implies numbers here are hexadecimal numbers. Is that right?– Stéphane Chazelas
Dec 6 at 9:10
It would be more helpful if your sample had more examples of things you don't want it to match (like what about
foo1.2
, foo-1.2
, 1.2-3
). How do you define word? How do you define number? 9c
being a number implies numbers here are hexadecimal numbers. Is that right?– Stéphane Chazelas
Dec 6 at 9:10
Why isn't
abcd
to be matched? That's an hexadecimal number as well. Is that because you need those words to contain at least two numbers?– Stéphane Chazelas
Dec 6 at 9:44
Why isn't
abcd
to be matched? That's an hexadecimal number as well. Is that because you need those words to contain at least two numbers?– Stéphane Chazelas
Dec 6 at 9:44
add a comment |
4 Answers
4
active
oldest
votes
up vote
0
down vote
Try this,
grep -E -o '[0-9].[0-9].[0-9].[0-9][^[:space:]]+' file
-E
Interpret PATTERN as an extended regular expression
-o
Print only the matched parts of a matching line
[^[:space:]]+
until white space
@StéphaneChazelas Thanks, updated fordot
, ...
– msp9011
Dec 6 at 9:11
@StéphaneChazelas i mentw+
as untile white space, sincew
followed by+
.... correct me if im wrong...
– msp9011
Dec 6 at 9:13
@StéphaneChazelas much thanks...
– msp9011
Dec 6 at 9:39
add a comment |
up vote
0
down vote
If by word, you mean sequence of non-whitespace characters, and by number, you mean hexadecimal (without sign or leading 0x
, so sequence of 0123456789abcdefABCDEF characters), and that you need at least two of those numbers per word (otherwise abcd
would be matched as well), with GNU grep
you can do:
grep -Pio '(?<!S)[0-9a-f]+(.[0-9a-f]+)+(?!S)'
Or with perl
:
perl -lne 'for (/S+/g) {print if /^[da-f]+(.[da-f]+)+$/}'
add a comment |
up vote
0
down vote
Assuming the values are inside a file, with pcre grep:
$ grep -P '(([0-9a-f]+).)(?1)+(?2)' file
9.0.8.2c
8.1.3.9b
Or with perl:
perl -lne '/((([da-f]+).)(?2)+(?3))/;print $1' file
add a comment |
up vote
0
down vote
Try also
grep -oE "(w*[.]w*)*" file
9.0.8.2c
8.1.3.9b
Perhaps end with+
instead of*
, to avoid matching the empty string? The output will be the same, but the*
form will report "success" even on files containing no such words.
– JigglyNaga
Dec 6 at 13:48
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',
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%2f486321%2fhow-to-extract-word-which-has-only-numbers-separated-by-dot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Try this,
grep -E -o '[0-9].[0-9].[0-9].[0-9][^[:space:]]+' file
-E
Interpret PATTERN as an extended regular expression
-o
Print only the matched parts of a matching line
[^[:space:]]+
until white space
@StéphaneChazelas Thanks, updated fordot
, ...
– msp9011
Dec 6 at 9:11
@StéphaneChazelas i mentw+
as untile white space, sincew
followed by+
.... correct me if im wrong...
– msp9011
Dec 6 at 9:13
@StéphaneChazelas much thanks...
– msp9011
Dec 6 at 9:39
add a comment |
up vote
0
down vote
Try this,
grep -E -o '[0-9].[0-9].[0-9].[0-9][^[:space:]]+' file
-E
Interpret PATTERN as an extended regular expression
-o
Print only the matched parts of a matching line
[^[:space:]]+
until white space
@StéphaneChazelas Thanks, updated fordot
, ...
– msp9011
Dec 6 at 9:11
@StéphaneChazelas i mentw+
as untile white space, sincew
followed by+
.... correct me if im wrong...
– msp9011
Dec 6 at 9:13
@StéphaneChazelas much thanks...
– msp9011
Dec 6 at 9:39
add a comment |
up vote
0
down vote
up vote
0
down vote
Try this,
grep -E -o '[0-9].[0-9].[0-9].[0-9][^[:space:]]+' file
-E
Interpret PATTERN as an extended regular expression
-o
Print only the matched parts of a matching line
[^[:space:]]+
until white space
Try this,
grep -E -o '[0-9].[0-9].[0-9].[0-9][^[:space:]]+' file
-E
Interpret PATTERN as an extended regular expression
-o
Print only the matched parts of a matching line
[^[:space:]]+
until white space
edited Dec 6 at 9:38
answered Dec 6 at 8:58
msp9011
3,65543863
3,65543863
@StéphaneChazelas Thanks, updated fordot
, ...
– msp9011
Dec 6 at 9:11
@StéphaneChazelas i mentw+
as untile white space, sincew
followed by+
.... correct me if im wrong...
– msp9011
Dec 6 at 9:13
@StéphaneChazelas much thanks...
– msp9011
Dec 6 at 9:39
add a comment |
@StéphaneChazelas Thanks, updated fordot
, ...
– msp9011
Dec 6 at 9:11
@StéphaneChazelas i mentw+
as untile white space, sincew
followed by+
.... correct me if im wrong...
– msp9011
Dec 6 at 9:13
@StéphaneChazelas much thanks...
– msp9011
Dec 6 at 9:39
@StéphaneChazelas Thanks, updated for
dot
, ...– msp9011
Dec 6 at 9:11
@StéphaneChazelas Thanks, updated for
dot
, ...– msp9011
Dec 6 at 9:11
@StéphaneChazelas i ment
w+
as untile white space, since w
followed by +
.... correct me if im wrong...– msp9011
Dec 6 at 9:13
@StéphaneChazelas i ment
w+
as untile white space, since w
followed by +
.... correct me if im wrong...– msp9011
Dec 6 at 9:13
@StéphaneChazelas much thanks...
– msp9011
Dec 6 at 9:39
@StéphaneChazelas much thanks...
– msp9011
Dec 6 at 9:39
add a comment |
up vote
0
down vote
If by word, you mean sequence of non-whitespace characters, and by number, you mean hexadecimal (without sign or leading 0x
, so sequence of 0123456789abcdefABCDEF characters), and that you need at least two of those numbers per word (otherwise abcd
would be matched as well), with GNU grep
you can do:
grep -Pio '(?<!S)[0-9a-f]+(.[0-9a-f]+)+(?!S)'
Or with perl
:
perl -lne 'for (/S+/g) {print if /^[da-f]+(.[da-f]+)+$/}'
add a comment |
up vote
0
down vote
If by word, you mean sequence of non-whitespace characters, and by number, you mean hexadecimal (without sign or leading 0x
, so sequence of 0123456789abcdefABCDEF characters), and that you need at least two of those numbers per word (otherwise abcd
would be matched as well), with GNU grep
you can do:
grep -Pio '(?<!S)[0-9a-f]+(.[0-9a-f]+)+(?!S)'
Or with perl
:
perl -lne 'for (/S+/g) {print if /^[da-f]+(.[da-f]+)+$/}'
add a comment |
up vote
0
down vote
up vote
0
down vote
If by word, you mean sequence of non-whitespace characters, and by number, you mean hexadecimal (without sign or leading 0x
, so sequence of 0123456789abcdefABCDEF characters), and that you need at least two of those numbers per word (otherwise abcd
would be matched as well), with GNU grep
you can do:
grep -Pio '(?<!S)[0-9a-f]+(.[0-9a-f]+)+(?!S)'
Or with perl
:
perl -lne 'for (/S+/g) {print if /^[da-f]+(.[da-f]+)+$/}'
If by word, you mean sequence of non-whitespace characters, and by number, you mean hexadecimal (without sign or leading 0x
, so sequence of 0123456789abcdefABCDEF characters), and that you need at least two of those numbers per word (otherwise abcd
would be matched as well), with GNU grep
you can do:
grep -Pio '(?<!S)[0-9a-f]+(.[0-9a-f]+)+(?!S)'
Or with perl
:
perl -lne 'for (/S+/g) {print if /^[da-f]+(.[da-f]+)+$/}'
answered Dec 6 at 9:49
Stéphane Chazelas
298k54562909
298k54562909
add a comment |
add a comment |
up vote
0
down vote
Assuming the values are inside a file, with pcre grep:
$ grep -P '(([0-9a-f]+).)(?1)+(?2)' file
9.0.8.2c
8.1.3.9b
Or with perl:
perl -lne '/((([da-f]+).)(?2)+(?3))/;print $1' file
add a comment |
up vote
0
down vote
Assuming the values are inside a file, with pcre grep:
$ grep -P '(([0-9a-f]+).)(?1)+(?2)' file
9.0.8.2c
8.1.3.9b
Or with perl:
perl -lne '/((([da-f]+).)(?2)+(?3))/;print $1' file
add a comment |
up vote
0
down vote
up vote
0
down vote
Assuming the values are inside a file, with pcre grep:
$ grep -P '(([0-9a-f]+).)(?1)+(?2)' file
9.0.8.2c
8.1.3.9b
Or with perl:
perl -lne '/((([da-f]+).)(?2)+(?3))/;print $1' file
Assuming the values are inside a file, with pcre grep:
$ grep -P '(([0-9a-f]+).)(?1)+(?2)' file
9.0.8.2c
8.1.3.9b
Or with perl:
perl -lne '/((([da-f]+).)(?2)+(?3))/;print $1' file
answered Dec 6 at 11:44
Isaac
11k11648
11k11648
add a comment |
add a comment |
up vote
0
down vote
Try also
grep -oE "(w*[.]w*)*" file
9.0.8.2c
8.1.3.9b
Perhaps end with+
instead of*
, to avoid matching the empty string? The output will be the same, but the*
form will report "success" even on files containing no such words.
– JigglyNaga
Dec 6 at 13:48
add a comment |
up vote
0
down vote
Try also
grep -oE "(w*[.]w*)*" file
9.0.8.2c
8.1.3.9b
Perhaps end with+
instead of*
, to avoid matching the empty string? The output will be the same, but the*
form will report "success" even on files containing no such words.
– JigglyNaga
Dec 6 at 13:48
add a comment |
up vote
0
down vote
up vote
0
down vote
Try also
grep -oE "(w*[.]w*)*" file
9.0.8.2c
8.1.3.9b
Try also
grep -oE "(w*[.]w*)*" file
9.0.8.2c
8.1.3.9b
answered Dec 6 at 12:28
RudiC
3,9541312
3,9541312
Perhaps end with+
instead of*
, to avoid matching the empty string? The output will be the same, but the*
form will report "success" even on files containing no such words.
– JigglyNaga
Dec 6 at 13:48
add a comment |
Perhaps end with+
instead of*
, to avoid matching the empty string? The output will be the same, but the*
form will report "success" even on files containing no such words.
– JigglyNaga
Dec 6 at 13:48
Perhaps end with
+
instead of *
, to avoid matching the empty string? The output will be the same, but the *
form will report "success" even on files containing no such words.– JigglyNaga
Dec 6 at 13:48
Perhaps end with
+
instead of *
, to avoid matching the empty string? The output will be the same, but the *
form will report "success" even on files containing no such words.– JigglyNaga
Dec 6 at 13:48
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.
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%2funix.stackexchange.com%2fquestions%2f486321%2fhow-to-extract-word-which-has-only-numbers-separated-by-dot%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
It would be more helpful if your sample had more examples of things you don't want it to match (like what about
foo1.2
,foo-1.2
,1.2-3
). How do you define word? How do you define number?9c
being a number implies numbers here are hexadecimal numbers. Is that right?– Stéphane Chazelas
Dec 6 at 9:10
Why isn't
abcd
to be matched? That's an hexadecimal number as well. Is that because you need those words to contain at least two numbers?– Stéphane Chazelas
Dec 6 at 9:44