egrep "[0-9]{2}" not working

martiniii

New Member
Joined
Jan 20, 2021
Messages
2
Reaction score
1
Credits
20
Hello, Im sorry to bother you with this, but I´m new to this and need help to get it working properly.
I need to get only the lines that don´t start with number and have two digit number in them.
I have this command:
cat /etc/group | egrep -v "^[0-9]" | egrep "[0-9]{2}"
And the problem is that it´s not showing only lines with two digit number. Good sign is that it´s showing lines with more than two digit. I tried also {2,2} and it´s doing the same think (showing lines with 2+ digit number)

thanks for your help
 


KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
5,781
Reaction score
5,224
Credits
46,661
Hmm....

This gets you a little closer - but we're gonna need Jas for this one.

cat /etc/group | grep -E '(^|[^0-9])[0-9]{2}($|[^0-9])'
 
OP
M

martiniii

New Member
Joined
Jan 20, 2021
Messages
2
Reaction score
1
Credits
20
I managed to get it working with
cat /etc/group | egrep -v "^[0-9]" | egrep "[0-9]{2}" | egrep -v "[0-9]{3}"
 

JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,450
Reaction score
2,056
Credits
10,088
Looks like I'm a little late to the party.
One thing:
When using grep, you don't need to use cat. You can just use grep on its own:
Bash:
egrep -v "^[0-9]" /etc/group | egrep "[0-9]{2}" | egrep -v "[0-9]{3}"
 

simba07565

New Member
Joined
Jan 23, 2021
Messages
2
Reaction score
1
Credits
10
Hello, Im sorry to bother you with this, but I´m new to this and need help to get it working properly.
I need to get only the lines that don´t start with number and have two digit number in them.
I have this command:
cat /etc/group | egrep -v "^[0-9]" | egrep "[0-9]{2}"
And the problem is that it´s not showing only lines with two digit number. Good sign is that it´s showing lines with more than two digit. I tried also {2,2} and it´s doing the same think (showing lines with 2+ digit number)

thanks for your help

Have you solved it?
 

wizardfromoz

Administrator
Staff member
Gold Supporter
Joined
Apr 30, 2017
Messages
7,115
Reaction score
5,993
Credits
23,554
Morning all, moving this to our Command Line subforum, where Jas has a lounge chair, slippers and pipe set up :)

https://linux.org/forums/command-line.145/

@martiniii , @KGIII , @JasKinasis and @simba07565 take note.

Hang on to your hats and we'll take a magic carpet ride there.

Wizard

BTW - Jas was a drummer with UK prog rock band Kinasis, now he is with No Thursday War but @JasNoThursdayWar doesn't have the same ring to it. Just start to type in @jas and the rest will autocomplete :)
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Members online


Top