Checking if the end of each line in the file is ending with a letter followed by 8 digits number

Clash Royale CLAN TAG#URR8PPP up vote
2
down vote
favorite
I have a problem with checking if each line of my files is ending with a letter (A-Z (always capital))followed by exatcly 8 digit numbers (doesnt matter which one). So I have a number of files and content of each file looks like this:
Nc1nc2cc3OCCOc3cc2s1 A10000001
CCN(CC)C1CCN(Cc2cc(I)cc(I)c2O)CC1 B100000002
CCN(CC)C1CCN(Cc2cc(cc(I)c2O)C#CCO)CC1 C10000003
There is always a space between this "string" and letter wtih numbers. So, in this example B100000002 there are 9 digits after letter. Since I done most of the things manually I would like to check if in my files there are errors. Can anybody help me with some bash command so I can see which lines have different, incorrect pattern?
Thanks!
bash text-processing
add a comment |Â
up vote
2
down vote
favorite
I have a problem with checking if each line of my files is ending with a letter (A-Z (always capital))followed by exatcly 8 digit numbers (doesnt matter which one). So I have a number of files and content of each file looks like this:
Nc1nc2cc3OCCOc3cc2s1 A10000001
CCN(CC)C1CCN(Cc2cc(I)cc(I)c2O)CC1 B100000002
CCN(CC)C1CCN(Cc2cc(cc(I)c2O)C#CCO)CC1 C10000003
There is always a space between this "string" and letter wtih numbers. So, in this example B100000002 there are 9 digits after letter. Since I done most of the things manually I would like to check if in my files there are errors. Can anybody help me with some bash command so I can see which lines have different, incorrect pattern?
Thanks!
bash text-processing
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have a problem with checking if each line of my files is ending with a letter (A-Z (always capital))followed by exatcly 8 digit numbers (doesnt matter which one). So I have a number of files and content of each file looks like this:
Nc1nc2cc3OCCOc3cc2s1 A10000001
CCN(CC)C1CCN(Cc2cc(I)cc(I)c2O)CC1 B100000002
CCN(CC)C1CCN(Cc2cc(cc(I)c2O)C#CCO)CC1 C10000003
There is always a space between this "string" and letter wtih numbers. So, in this example B100000002 there are 9 digits after letter. Since I done most of the things manually I would like to check if in my files there are errors. Can anybody help me with some bash command so I can see which lines have different, incorrect pattern?
Thanks!
bash text-processing
I have a problem with checking if each line of my files is ending with a letter (A-Z (always capital))followed by exatcly 8 digit numbers (doesnt matter which one). So I have a number of files and content of each file looks like this:
Nc1nc2cc3OCCOc3cc2s1 A10000001
CCN(CC)C1CCN(Cc2cc(I)cc(I)c2O)CC1 B100000002
CCN(CC)C1CCN(Cc2cc(cc(I)c2O)C#CCO)CC1 C10000003
There is always a space between this "string" and letter wtih numbers. So, in this example B100000002 there are 9 digits after letter. Since I done most of the things manually I would like to check if in my files there are errors. Can anybody help me with some bash command so I can see which lines have different, incorrect pattern?
Thanks!
bash text-processing
asked May 14 at 14:30
sergio
565
565
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
You can use grep to get the lines that don't follow the rule:
grep -v ' [[:upper:]][0-9]8$' file*
- space matches itself
[[:upper:]]is matched by any uppercase letter[0-9]matches a digit8is a "quantifier", it means the preceding construct must be repeated 8 times$matches at the end of line-vshows the lines that are not matched
1
"...get the lines that don't follow the rule" ? Wouldn't that also need-vflag forgrep -vto match lines that don't follow the pattern ?
â Sergiy Kolodyazhnyy
May 14 at 15:56
you are right, when I add-vthen script applies to all lines, without it, it just greps some of them..
â sergio
May 15 at 1:26
add a comment |Â
up vote
0
down vote
you could grep with a perl regexp:
grep -P ' [a-zA-Z]1[0-9]8$'
-P : for perl Regular expression
: the regexp starts with a space, because you want a space before the uppercase letter
[a-zA-Z]1 : Exactly 1 alphbaetic char lowercase or uppercase (you can remove a-z for uppercase only ie [A-Z]1)
[0-9]8 : exactly 8 numeric chars
$ : end of line
If you want to display the lines that does not match the pattern, just add the -v option to the grep command.
If you want to display lines numbers, add the -n option.
grep -Pvn ' [a-zA-Z]1[0-9]8$'
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
You can use grep to get the lines that don't follow the rule:
grep -v ' [[:upper:]][0-9]8$' file*
- space matches itself
[[:upper:]]is matched by any uppercase letter[0-9]matches a digit8is a "quantifier", it means the preceding construct must be repeated 8 times$matches at the end of line-vshows the lines that are not matched
1
"...get the lines that don't follow the rule" ? Wouldn't that also need-vflag forgrep -vto match lines that don't follow the pattern ?
â Sergiy Kolodyazhnyy
May 14 at 15:56
you are right, when I add-vthen script applies to all lines, without it, it just greps some of them..
â sergio
May 15 at 1:26
add a comment |Â
up vote
3
down vote
You can use grep to get the lines that don't follow the rule:
grep -v ' [[:upper:]][0-9]8$' file*
- space matches itself
[[:upper:]]is matched by any uppercase letter[0-9]matches a digit8is a "quantifier", it means the preceding construct must be repeated 8 times$matches at the end of line-vshows the lines that are not matched
1
"...get the lines that don't follow the rule" ? Wouldn't that also need-vflag forgrep -vto match lines that don't follow the pattern ?
â Sergiy Kolodyazhnyy
May 14 at 15:56
you are right, when I add-vthen script applies to all lines, without it, it just greps some of them..
â sergio
May 15 at 1:26
add a comment |Â
up vote
3
down vote
up vote
3
down vote
You can use grep to get the lines that don't follow the rule:
grep -v ' [[:upper:]][0-9]8$' file*
- space matches itself
[[:upper:]]is matched by any uppercase letter[0-9]matches a digit8is a "quantifier", it means the preceding construct must be repeated 8 times$matches at the end of line-vshows the lines that are not matched
You can use grep to get the lines that don't follow the rule:
grep -v ' [[:upper:]][0-9]8$' file*
- space matches itself
[[:upper:]]is matched by any uppercase letter[0-9]matches a digit8is a "quantifier", it means the preceding construct must be repeated 8 times$matches at the end of line-vshows the lines that are not matched
edited May 15 at 10:05
answered May 14 at 14:54
choroba
5,89411726
5,89411726
1
"...get the lines that don't follow the rule" ? Wouldn't that also need-vflag forgrep -vto match lines that don't follow the pattern ?
â Sergiy Kolodyazhnyy
May 14 at 15:56
you are right, when I add-vthen script applies to all lines, without it, it just greps some of them..
â sergio
May 15 at 1:26
add a comment |Â
1
"...get the lines that don't follow the rule" ? Wouldn't that also need-vflag forgrep -vto match lines that don't follow the pattern ?
â Sergiy Kolodyazhnyy
May 14 at 15:56
you are right, when I add-vthen script applies to all lines, without it, it just greps some of them..
â sergio
May 15 at 1:26
1
1
"...get the lines that don't follow the rule" ? Wouldn't that also need
-v flag for grep -v to match lines that don't follow the pattern ?â Sergiy Kolodyazhnyy
May 14 at 15:56
"...get the lines that don't follow the rule" ? Wouldn't that also need
-v flag for grep -v to match lines that don't follow the pattern ?â Sergiy Kolodyazhnyy
May 14 at 15:56
you are right, when I add
-v then script applies to all lines, without it, it just greps some of them..â sergio
May 15 at 1:26
you are right, when I add
-v then script applies to all lines, without it, it just greps some of them..â sergio
May 15 at 1:26
add a comment |Â
up vote
0
down vote
you could grep with a perl regexp:
grep -P ' [a-zA-Z]1[0-9]8$'
-P : for perl Regular expression
: the regexp starts with a space, because you want a space before the uppercase letter
[a-zA-Z]1 : Exactly 1 alphbaetic char lowercase or uppercase (you can remove a-z for uppercase only ie [A-Z]1)
[0-9]8 : exactly 8 numeric chars
$ : end of line
If you want to display the lines that does not match the pattern, just add the -v option to the grep command.
If you want to display lines numbers, add the -n option.
grep -Pvn ' [a-zA-Z]1[0-9]8$'
add a comment |Â
up vote
0
down vote
you could grep with a perl regexp:
grep -P ' [a-zA-Z]1[0-9]8$'
-P : for perl Regular expression
: the regexp starts with a space, because you want a space before the uppercase letter
[a-zA-Z]1 : Exactly 1 alphbaetic char lowercase or uppercase (you can remove a-z for uppercase only ie [A-Z]1)
[0-9]8 : exactly 8 numeric chars
$ : end of line
If you want to display the lines that does not match the pattern, just add the -v option to the grep command.
If you want to display lines numbers, add the -n option.
grep -Pvn ' [a-zA-Z]1[0-9]8$'
add a comment |Â
up vote
0
down vote
up vote
0
down vote
you could grep with a perl regexp:
grep -P ' [a-zA-Z]1[0-9]8$'
-P : for perl Regular expression
: the regexp starts with a space, because you want a space before the uppercase letter
[a-zA-Z]1 : Exactly 1 alphbaetic char lowercase or uppercase (you can remove a-z for uppercase only ie [A-Z]1)
[0-9]8 : exactly 8 numeric chars
$ : end of line
If you want to display the lines that does not match the pattern, just add the -v option to the grep command.
If you want to display lines numbers, add the -n option.
grep -Pvn ' [a-zA-Z]1[0-9]8$'
you could grep with a perl regexp:
grep -P ' [a-zA-Z]1[0-9]8$'
-P : for perl Regular expression
: the regexp starts with a space, because you want a space before the uppercase letter
[a-zA-Z]1 : Exactly 1 alphbaetic char lowercase or uppercase (you can remove a-z for uppercase only ie [A-Z]1)
[0-9]8 : exactly 8 numeric chars
$ : end of line
If you want to display the lines that does not match the pattern, just add the -v option to the grep command.
If you want to display lines numbers, add the -n option.
grep -Pvn ' [a-zA-Z]1[0-9]8$'
answered May 14 at 15:01
cmak.fr
1,539918
1,539918
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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%2faskubuntu.com%2fquestions%2f1036148%2fchecking-if-the-end-of-each-line-in-the-file-is-ending-with-a-letter-followed-by%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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