The Linux Community Forum

The Forums => General Discussion => Topic started by: ahsw on November 25, 2019, 03:37:07 am

Title: Help with command to find username with less than 8 characters
Post by: ahsw on November 25, 2019, 03:37:07 am
I just started taking a linux course and am stuck with my assignment.

I need to find the usernames of logged-in users with usernames of fewer than 8 characters. Here is the command that I have tried but it is not working. Would someone please advise what I may have done incorrectly?
Quote
who | grep '[a-zA-Z0-9]\{1,7\}'

The following command here returns 8 character usernames (I have tested and it works)
Quote
who | grep '[a-zA-Z0-9]\{8\}'
Title: Re: Help with command to find username with less than 8 characters
Post by: Mark Greaves (PCNetSpec) on November 25, 2019, 05:45:58 am
I'm lost why your last command doesn't work if it has to be FEWER than 8 characters (?)
Code: [Select]
who | grep '[a-zA-Z0-9]\{8\}'
should do <=7 characters (and skip anything with >=8)  .. so what am I missing ?
Title: Re: Help with command to find username with less than 8 characters
Post by: Zorba61 on November 25, 2019, 09:38:54 am
I ran the command line on my pc and it worked. :)
Title: Re: Help with command to find username with less than 8 characters
Post by: ahsw on November 26, 2019, 04:58:07 am
So I tried this
Code: [Select]
who | grep "^[a-z0-9]\{1,7\}\s"
and it works!!
FWIW I am using MacOS.
Title: Re: Help with command to find username with less than 8 characters
Post by: Zorba61 on November 26, 2019, 09:39:03 am
 :-X :-X :-X
SimplePortal 2.3.3 © 2008-2010, SimplePortal