Filter list based on number of digits in strings
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I have long list of entries are recorded in a file, something like this short list:
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
6846DFEC-C0A2-11E8-B7A8-3ECB9C0CC049
6846DFEC-C0A2-11E8-B7A8-3ECB9C0CC049
. . . .
. . . .
. . . .
I want to filter this list based on the number of digits within each entry and if the number of digits more than a specific threshold then keep the string otherwise remove it. in the previous example, how can I keep all the entries that have 18 digits in its names?
Expected out put:
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
Very big probelm here please help!!!
bash
add a comment |Â
up vote
2
down vote
favorite
I have long list of entries are recorded in a file, something like this short list:
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
6846DFEC-C0A2-11E8-B7A8-3ECB9C0CC049
6846DFEC-C0A2-11E8-B7A8-3ECB9C0CC049
. . . .
. . . .
. . . .
I want to filter this list based on the number of digits within each entry and if the number of digits more than a specific threshold then keep the string otherwise remove it. in the previous example, how can I keep all the entries that have 18 digits in its names?
Expected out put:
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
Very big probelm here please help!!!
bash
1
All of those have 32 digits; they just happen to be hexidecimal digits.
â DopeGhoti
3 hours ago
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have long list of entries are recorded in a file, something like this short list:
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
6846DFEC-C0A2-11E8-B7A8-3ECB9C0CC049
6846DFEC-C0A2-11E8-B7A8-3ECB9C0CC049
. . . .
. . . .
. . . .
I want to filter this list based on the number of digits within each entry and if the number of digits more than a specific threshold then keep the string otherwise remove it. in the previous example, how can I keep all the entries that have 18 digits in its names?
Expected out put:
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
Very big probelm here please help!!!
bash
I have long list of entries are recorded in a file, something like this short list:
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
6846DFEC-C0A2-11E8-B7A8-3ECB9C0CC049
6846DFEC-C0A2-11E8-B7A8-3ECB9C0CC049
. . . .
. . . .
. . . .
I want to filter this list based on the number of digits within each entry and if the number of digits more than a specific threshold then keep the string otherwise remove it. in the previous example, how can I keep all the entries that have 18 digits in its names?
Expected out put:
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
Very big probelm here please help!!!
bash
bash
asked 3 hours ago
Zahi
956
956
1
All of those have 32 digits; they just happen to be hexidecimal digits.
â DopeGhoti
3 hours ago
add a comment |Â
1
All of those have 32 digits; they just happen to be hexidecimal digits.
â DopeGhoti
3 hours ago
1
1
All of those have 32 digits; they just happen to be hexidecimal digits.
â DopeGhoti
3 hours ago
All of those have 32 digits; they just happen to be hexidecimal digits.
â DopeGhoti
3 hours ago
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
4
down vote
With awk
:
awk -F '[[:digit:]]' 'NF > 18'
We use digits as the field separator, so the number of fields will be one plus the number of digits (x1y
is split into x
and y
), so above we're looking for lines that have at least 18 digits.
(with mawk
, replace [:digit:]
with 0-9
. mawk
doesn't support POSIX character classes, but it's [0-9]
contrary to other awk
implementations matches on 0123456789 only regardless of the locale. Portably, you can use [0123456789]
, or you can use [0-9]
is you know the text doesn't contain non-ASCII data).
For lines that have exactly 18 digits, that would be:
awk -F '[[:digit:]]' 'NF == 19'
With sed
, for at least 18 digits:
sed -e 's/[[:digit:]]/&/18;t' -e d
With grep
:
grep -E '(.*[[:digit:]])18'
add a comment |Â
up vote
1
down vote
Let's say that the data are saved in a file called file.txt
, then you can do something like:
#!/bin/bash
cat file.txt | while IFS= read line; do
n=$(echo $line | awk 'print gsub("[0-9]", "")')
if [[ $n -gt 17 ]]; then
echo $line
fi
done
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
Or
awk 'gsub("[0-9]", "&") >= 18'
or, more directly,awk 'if (gsub("[0-9]", "") > 17) print;' < file.txt
â Jeff Schaller
3 hours ago
2
@JeffSchaller, you'd wantawk 'gsub("[0-9]", "&") >= 18'
instead.
â Stéphane Chazelas
3 hours ago
@Stéphane Chazelas. Correct thanks!
â Goro
3 hours ago
@Jeff Schaller I really don't know, this is what come to mind, very old style ;-)
â Goro
3 hours ago
add a comment |Â
up vote
0
down vote
How about using the return value of perl's tr
(similar to using the returnvalue of awk's gsub
)
$ perl -ne 'print if tr0-90-9 >= 18' file
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
With awk
:
awk -F '[[:digit:]]' 'NF > 18'
We use digits as the field separator, so the number of fields will be one plus the number of digits (x1y
is split into x
and y
), so above we're looking for lines that have at least 18 digits.
(with mawk
, replace [:digit:]
with 0-9
. mawk
doesn't support POSIX character classes, but it's [0-9]
contrary to other awk
implementations matches on 0123456789 only regardless of the locale. Portably, you can use [0123456789]
, or you can use [0-9]
is you know the text doesn't contain non-ASCII data).
For lines that have exactly 18 digits, that would be:
awk -F '[[:digit:]]' 'NF == 19'
With sed
, for at least 18 digits:
sed -e 's/[[:digit:]]/&/18;t' -e d
With grep
:
grep -E '(.*[[:digit:]])18'
add a comment |Â
up vote
4
down vote
With awk
:
awk -F '[[:digit:]]' 'NF > 18'
We use digits as the field separator, so the number of fields will be one plus the number of digits (x1y
is split into x
and y
), so above we're looking for lines that have at least 18 digits.
(with mawk
, replace [:digit:]
with 0-9
. mawk
doesn't support POSIX character classes, but it's [0-9]
contrary to other awk
implementations matches on 0123456789 only regardless of the locale. Portably, you can use [0123456789]
, or you can use [0-9]
is you know the text doesn't contain non-ASCII data).
For lines that have exactly 18 digits, that would be:
awk -F '[[:digit:]]' 'NF == 19'
With sed
, for at least 18 digits:
sed -e 's/[[:digit:]]/&/18;t' -e d
With grep
:
grep -E '(.*[[:digit:]])18'
add a comment |Â
up vote
4
down vote
up vote
4
down vote
With awk
:
awk -F '[[:digit:]]' 'NF > 18'
We use digits as the field separator, so the number of fields will be one plus the number of digits (x1y
is split into x
and y
), so above we're looking for lines that have at least 18 digits.
(with mawk
, replace [:digit:]
with 0-9
. mawk
doesn't support POSIX character classes, but it's [0-9]
contrary to other awk
implementations matches on 0123456789 only regardless of the locale. Portably, you can use [0123456789]
, or you can use [0-9]
is you know the text doesn't contain non-ASCII data).
For lines that have exactly 18 digits, that would be:
awk -F '[[:digit:]]' 'NF == 19'
With sed
, for at least 18 digits:
sed -e 's/[[:digit:]]/&/18;t' -e d
With grep
:
grep -E '(.*[[:digit:]])18'
With awk
:
awk -F '[[:digit:]]' 'NF > 18'
We use digits as the field separator, so the number of fields will be one plus the number of digits (x1y
is split into x
and y
), so above we're looking for lines that have at least 18 digits.
(with mawk
, replace [:digit:]
with 0-9
. mawk
doesn't support POSIX character classes, but it's [0-9]
contrary to other awk
implementations matches on 0123456789 only regardless of the locale. Portably, you can use [0123456789]
, or you can use [0-9]
is you know the text doesn't contain non-ASCII data).
For lines that have exactly 18 digits, that would be:
awk -F '[[:digit:]]' 'NF == 19'
With sed
, for at least 18 digits:
sed -e 's/[[:digit:]]/&/18;t' -e d
With grep
:
grep -E '(.*[[:digit:]])18'
edited 3 hours ago
answered 3 hours ago
Stéphane Chazelas
286k53528866
286k53528866
add a comment |Â
add a comment |Â
up vote
1
down vote
Let's say that the data are saved in a file called file.txt
, then you can do something like:
#!/bin/bash
cat file.txt | while IFS= read line; do
n=$(echo $line | awk 'print gsub("[0-9]", "")')
if [[ $n -gt 17 ]]; then
echo $line
fi
done
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
Or
awk 'gsub("[0-9]", "&") >= 18'
or, more directly,awk 'if (gsub("[0-9]", "") > 17) print;' < file.txt
â Jeff Schaller
3 hours ago
2
@JeffSchaller, you'd wantawk 'gsub("[0-9]", "&") >= 18'
instead.
â Stéphane Chazelas
3 hours ago
@Stéphane Chazelas. Correct thanks!
â Goro
3 hours ago
@Jeff Schaller I really don't know, this is what come to mind, very old style ;-)
â Goro
3 hours ago
add a comment |Â
up vote
1
down vote
Let's say that the data are saved in a file called file.txt
, then you can do something like:
#!/bin/bash
cat file.txt | while IFS= read line; do
n=$(echo $line | awk 'print gsub("[0-9]", "")')
if [[ $n -gt 17 ]]; then
echo $line
fi
done
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
Or
awk 'gsub("[0-9]", "&") >= 18'
or, more directly,awk 'if (gsub("[0-9]", "") > 17) print;' < file.txt
â Jeff Schaller
3 hours ago
2
@JeffSchaller, you'd wantawk 'gsub("[0-9]", "&") >= 18'
instead.
â Stéphane Chazelas
3 hours ago
@Stéphane Chazelas. Correct thanks!
â Goro
3 hours ago
@Jeff Schaller I really don't know, this is what come to mind, very old style ;-)
â Goro
3 hours ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Let's say that the data are saved in a file called file.txt
, then you can do something like:
#!/bin/bash
cat file.txt | while IFS= read line; do
n=$(echo $line | awk 'print gsub("[0-9]", "")')
if [[ $n -gt 17 ]]; then
echo $line
fi
done
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
Or
awk 'gsub("[0-9]", "&") >= 18'
Let's say that the data are saved in a file called file.txt
, then you can do something like:
#!/bin/bash
cat file.txt | while IFS= read line; do
n=$(echo $line | awk 'print gsub("[0-9]", "")')
if [[ $n -gt 17 ]]; then
echo $line
fi
done
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
Or
awk 'gsub("[0-9]", "&") >= 18'
edited 3 hours ago
answered 3 hours ago
Goro
5,05552459
5,05552459
or, more directly,awk 'if (gsub("[0-9]", "") > 17) print;' < file.txt
â Jeff Schaller
3 hours ago
2
@JeffSchaller, you'd wantawk 'gsub("[0-9]", "&") >= 18'
instead.
â Stéphane Chazelas
3 hours ago
@Stéphane Chazelas. Correct thanks!
â Goro
3 hours ago
@Jeff Schaller I really don't know, this is what come to mind, very old style ;-)
â Goro
3 hours ago
add a comment |Â
or, more directly,awk 'if (gsub("[0-9]", "") > 17) print;' < file.txt
â Jeff Schaller
3 hours ago
2
@JeffSchaller, you'd wantawk 'gsub("[0-9]", "&") >= 18'
instead.
â Stéphane Chazelas
3 hours ago
@Stéphane Chazelas. Correct thanks!
â Goro
3 hours ago
@Jeff Schaller I really don't know, this is what come to mind, very old style ;-)
â Goro
3 hours ago
or, more directly,
awk 'if (gsub("[0-9]", "") > 17) print;' < file.txt
â Jeff Schaller
3 hours ago
or, more directly,
awk 'if (gsub("[0-9]", "") > 17) print;' < file.txt
â Jeff Schaller
3 hours ago
2
2
@JeffSchaller, you'd want
awk 'gsub("[0-9]", "&") >= 18'
instead.â Stéphane Chazelas
3 hours ago
@JeffSchaller, you'd want
awk 'gsub("[0-9]", "&") >= 18'
instead.â Stéphane Chazelas
3 hours ago
@Stéphane Chazelas. Correct thanks!
â Goro
3 hours ago
@Stéphane Chazelas. Correct thanks!
â Goro
3 hours ago
@Jeff Schaller I really don't know, this is what come to mind, very old style ;-)
â Goro
3 hours ago
@Jeff Schaller I really don't know, this is what come to mind, very old style ;-)
â Goro
3 hours ago
add a comment |Â
up vote
0
down vote
How about using the return value of perl's tr
(similar to using the returnvalue of awk's gsub
)
$ perl -ne 'print if tr0-90-9 >= 18' file
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
add a comment |Â
up vote
0
down vote
How about using the return value of perl's tr
(similar to using the returnvalue of awk's gsub
)
$ perl -ne 'print if tr0-90-9 >= 18' file
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
add a comment |Â
up vote
0
down vote
up vote
0
down vote
How about using the return value of perl's tr
(similar to using the returnvalue of awk's gsub
)
$ perl -ne 'print if tr0-90-9 >= 18' file
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
How about using the return value of perl's tr
(similar to using the returnvalue of awk's gsub
)
$ perl -ne 'print if tr0-90-9 >= 18' file
FFF1B976-9DDE-11E7-9C3D-6241D7D553BE
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
682D9DB6-C0A2-11E8-B7A8-3ECB9C0CC049
answered 2 mins ago
steeldriver
32.2k34979
32.2k34979
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472106%2ffilter-list-based-on-number-of-digits-in-strings%23new-answer', 'question_page');
);
Post as a guest
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
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
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
1
All of those have 32 digits; they just happen to be hexidecimal digits.
â DopeGhoti
3 hours ago