Author Topic: Help with command to find username with less than 8 characters  (Read 272 times)

0 Members and 1 Guest are viewing this topic.

Offline ahsw

  • Jr. Member
  • **
  • Posts: 2
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
Help with command to find username with less than 8 characters
« 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\}'

Offline Mark Greaves (PCNetSpec)

  • Administrator
  • Hero Member
  • *****
  • Posts: 18269
  • Karma: 477
  • Gender: Male
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
    • Awards
Re: Help with command to find username with less than 8 characters
« Reply #1 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 ?
« Last Edit: November 26, 2019, 12:32:58 am by Mark Greaves (PCNetSpec) »
WARNING: You are logged into reality as 'root'
logging in as 'insane' is the only safe option.
pcnetspec.co.uk

Offline Zorba61

  • Jr. Member
  • **
  • Posts: 97
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
Re: Help with command to find username with less than 8 characters
« Reply #2 on: November 25, 2019, 09:38:54 am »
I ran the command line on my pc and it worked. :)

Offline ahsw

  • Jr. Member
  • **
  • Posts: 2
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
Re: Help with command to find username with less than 8 characters
« Reply #3 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.

Offline Zorba61

  • Jr. Member
  • **
  • Posts: 97
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
Re: Help with command to find username with less than 8 characters
« Reply #4 on: November 26, 2019, 09:39:03 am »
 :-X :-X :-X

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal