Find animal-060, animal-061, animal-062 …, animal-069 in .txt using linux terminal
I want to find the string animal-0** in a .txt document using the linux terminal. ** are the numbers from 60 to 69. I guess I have to use grep and regex with the command: grep -E 'animal-0[60-69]'
animallist.txt
Would this be the correct command, or would it also find ima6 for example, because ima60 is part of the numbers and letters in the ''.
Sorry for grammar mistakes, English is not my native language.
regex linux terminal grep
add a comment |
I want to find the string animal-0** in a .txt document using the linux terminal. ** are the numbers from 60 to 69. I guess I have to use grep and regex with the command: grep -E 'animal-0[60-69]'
animallist.txt
Would this be the correct command, or would it also find ima6 for example, because ima60 is part of the numbers and letters in the ''.
Sorry for grammar mistakes, English is not my native language.
regex linux terminal grep
Thanks for editing, can I only do this by marking my text and use the {} button or also by writing my text in brackets? {test} meta.stackexchange.com/questions/22186/… I cant find the editor on the picture in the link, where is it? ^^
– Joe Th
Nov 15 '18 at 1:09
stackoverflow.com/editing-help - does that help?
– tink
Nov 15 '18 at 1:22
add a comment |
I want to find the string animal-0** in a .txt document using the linux terminal. ** are the numbers from 60 to 69. I guess I have to use grep and regex with the command: grep -E 'animal-0[60-69]'
animallist.txt
Would this be the correct command, or would it also find ima6 for example, because ima60 is part of the numbers and letters in the ''.
Sorry for grammar mistakes, English is not my native language.
regex linux terminal grep
I want to find the string animal-0** in a .txt document using the linux terminal. ** are the numbers from 60 to 69. I guess I have to use grep and regex with the command: grep -E 'animal-0[60-69]'
animallist.txt
Would this be the correct command, or would it also find ima6 for example, because ima60 is part of the numbers and letters in the ''.
Sorry for grammar mistakes, English is not my native language.
regex linux terminal grep
regex linux terminal grep
edited Nov 15 '18 at 0:50
tink
6,69332634
6,69332634
asked Nov 15 '18 at 0:33
Joe ThJoe Th
102
102
Thanks for editing, can I only do this by marking my text and use the {} button or also by writing my text in brackets? {test} meta.stackexchange.com/questions/22186/… I cant find the editor on the picture in the link, where is it? ^^
– Joe Th
Nov 15 '18 at 1:09
stackoverflow.com/editing-help - does that help?
– tink
Nov 15 '18 at 1:22
add a comment |
Thanks for editing, can I only do this by marking my text and use the {} button or also by writing my text in brackets? {test} meta.stackexchange.com/questions/22186/… I cant find the editor on the picture in the link, where is it? ^^
– Joe Th
Nov 15 '18 at 1:09
stackoverflow.com/editing-help - does that help?
– tink
Nov 15 '18 at 1:22
Thanks for editing, can I only do this by marking my text and use the {} button or also by writing my text in brackets? {test} meta.stackexchange.com/questions/22186/… I cant find the editor on the picture in the link, where is it? ^^
– Joe Th
Nov 15 '18 at 1:09
Thanks for editing, can I only do this by marking my text and use the {} button or also by writing my text in brackets? {test} meta.stackexchange.com/questions/22186/… I cant find the editor on the picture in the link, where is it? ^^
– Joe Th
Nov 15 '18 at 1:09
stackoverflow.com/editing-help - does that help?
– tink
Nov 15 '18 at 1:22
stackoverflow.com/editing-help - does that help?
– tink
Nov 15 '18 at 1:22
add a comment |
3 Answers
3
active
oldest
votes
You're pretty close! Remember that a regex character classes (sets or ranges between square brackets) look for a range of characters and will match just once unless you specify otherwise with *
or +
etc. In your example, [60-69]
is the same as [690-6]
which will match any single 6
, 9
, or charater in the range 0-6
.
To find the numbers between 60 and 69, we must look at the numbers as a string.
Take this as an example: Instead of "60" to "69", let's assume we are looking for "Za" to "Zj". In this case we would use the pattern Z[a-j]
.
Using the above example on your problem, we can take "6" instead of "Z" and replace "a-j" with "0-9", giving us the pattern:
animal-06[0-9]
As a complete command, this would be:
grep -E 'animal-06[0-9]' animallist.txt
add a comment |
Yes if you will use grep -E 'animal-06[0-9]' animallist.txt
it will work
add a comment |
grep -E 'animal-06[0-9]' animallist.txt
And no, it wouldn't find ima60. Your [60-69] won't do what you think, either. Find a good resource that teaches RegEx.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f53310818%2ffind-animal-060-animal-061-animal-062-animal-069-in-txt-using-linux-term%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
You're pretty close! Remember that a regex character classes (sets or ranges between square brackets) look for a range of characters and will match just once unless you specify otherwise with *
or +
etc. In your example, [60-69]
is the same as [690-6]
which will match any single 6
, 9
, or charater in the range 0-6
.
To find the numbers between 60 and 69, we must look at the numbers as a string.
Take this as an example: Instead of "60" to "69", let's assume we are looking for "Za" to "Zj". In this case we would use the pattern Z[a-j]
.
Using the above example on your problem, we can take "6" instead of "Z" and replace "a-j" with "0-9", giving us the pattern:
animal-06[0-9]
As a complete command, this would be:
grep -E 'animal-06[0-9]' animallist.txt
add a comment |
You're pretty close! Remember that a regex character classes (sets or ranges between square brackets) look for a range of characters and will match just once unless you specify otherwise with *
or +
etc. In your example, [60-69]
is the same as [690-6]
which will match any single 6
, 9
, or charater in the range 0-6
.
To find the numbers between 60 and 69, we must look at the numbers as a string.
Take this as an example: Instead of "60" to "69", let's assume we are looking for "Za" to "Zj". In this case we would use the pattern Z[a-j]
.
Using the above example on your problem, we can take "6" instead of "Z" and replace "a-j" with "0-9", giving us the pattern:
animal-06[0-9]
As a complete command, this would be:
grep -E 'animal-06[0-9]' animallist.txt
add a comment |
You're pretty close! Remember that a regex character classes (sets or ranges between square brackets) look for a range of characters and will match just once unless you specify otherwise with *
or +
etc. In your example, [60-69]
is the same as [690-6]
which will match any single 6
, 9
, or charater in the range 0-6
.
To find the numbers between 60 and 69, we must look at the numbers as a string.
Take this as an example: Instead of "60" to "69", let's assume we are looking for "Za" to "Zj". In this case we would use the pattern Z[a-j]
.
Using the above example on your problem, we can take "6" instead of "Z" and replace "a-j" with "0-9", giving us the pattern:
animal-06[0-9]
As a complete command, this would be:
grep -E 'animal-06[0-9]' animallist.txt
You're pretty close! Remember that a regex character classes (sets or ranges between square brackets) look for a range of characters and will match just once unless you specify otherwise with *
or +
etc. In your example, [60-69]
is the same as [690-6]
which will match any single 6
, 9
, or charater in the range 0-6
.
To find the numbers between 60 and 69, we must look at the numbers as a string.
Take this as an example: Instead of "60" to "69", let's assume we are looking for "Za" to "Zj". In this case we would use the pattern Z[a-j]
.
Using the above example on your problem, we can take "6" instead of "Z" and replace "a-j" with "0-9", giving us the pattern:
animal-06[0-9]
As a complete command, this would be:
grep -E 'animal-06[0-9]' animallist.txt
answered Nov 15 '18 at 0:49
Kind StrangerKind Stranger
1,054718
1,054718
add a comment |
add a comment |
Yes if you will use grep -E 'animal-06[0-9]' animallist.txt
it will work
add a comment |
Yes if you will use grep -E 'animal-06[0-9]' animallist.txt
it will work
add a comment |
Yes if you will use grep -E 'animal-06[0-9]' animallist.txt
it will work
Yes if you will use grep -E 'animal-06[0-9]' animallist.txt
it will work
answered Nov 15 '18 at 1:16
Salvatore CaramazzaSalvatore Caramazza
11
11
add a comment |
add a comment |
grep -E 'animal-06[0-9]' animallist.txt
And no, it wouldn't find ima60. Your [60-69] won't do what you think, either. Find a good resource that teaches RegEx.
add a comment |
grep -E 'animal-06[0-9]' animallist.txt
And no, it wouldn't find ima60. Your [60-69] won't do what you think, either. Find a good resource that teaches RegEx.
add a comment |
grep -E 'animal-06[0-9]' animallist.txt
And no, it wouldn't find ima60. Your [60-69] won't do what you think, either. Find a good resource that teaches RegEx.
grep -E 'animal-06[0-9]' animallist.txt
And no, it wouldn't find ima60. Your [60-69] won't do what you think, either. Find a good resource that teaches RegEx.
answered Nov 15 '18 at 0:49
tinktink
6,69332634
6,69332634
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f53310818%2ffind-animal-060-animal-061-animal-062-animal-069-in-txt-using-linux-term%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
Thanks for editing, can I only do this by marking my text and use the {} button or also by writing my text in brackets? {test} meta.stackexchange.com/questions/22186/… I cant find the editor on the picture in the link, where is it? ^^
– Joe Th
Nov 15 '18 at 1:09
stackoverflow.com/editing-help - does that help?
– tink
Nov 15 '18 at 1:22