School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,116 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,996 people online right now. Registration is fast and FREE... Join Now!




Basic Command line in unix

 

Basic Command line in unix

machaoxxx

23 Sep, 2009 - 12:04 PM
Post #1

New D.I.C Head
*

Joined: 23 Sep, 2009
Posts: 1

i just started learning about unix and such, and i'm trying out these problem i found online. Just tell me if i'm getting this. Currently downloading Untubun to run unix os on my comp.

problem: find all logged-in users with usernames of at least four characters.
$ who | cut -c1-8 | [a-zA-Z]\{4,\}$

so what should display if i use who is:
[Person name] [sum stuff] [date] [time]
ex:
Tomf Xyz23 23/23/23 23:23
Tam Xyz23 23/23/23 23:32
lomg Xyz23 23/23/23 23:32
jay Xyz23 23/23/23 23:32

a.) who display above
b.) using cut , i should i extract the first 1 to 8th character
c.) then match any alphabetical character that at least 4 character long
d.) and the $ mean to do for each line

This post has been edited by machaoxxx: 23 Sep, 2009 - 12:09 PM

User is offlineProfile CardPM
+Quote Post


moopet

RE: Basic Command Line In Unix

23 Sep, 2009 - 01:17 PM
Post #2

D.I.C Regular
***

Joined: 2 Apr, 2009
Posts: 348



Thanked: 34 times
My Contributions
QUOTE(machaoxxx @ 23 Sep, 2009 - 07:04 PM) *

$ who | cut -c1-8 | [a-zA-Z]\{4,\}$
a.) who display above
b.) using cut , i should i extract the first 1 to 8th character
c.) then match any alphabetical character that at least 4 character long
d.) and the $ mean to do for each line


Well, your cut is probably ok, depends on what your version of who I guess.

As far as your matching goes, you can't just shove a regular expression on the end of the line, you need to use a command to search on it. Your winner here is grep:
CODE

who | cut -c1-8 | grep '[a-zA-Z]\{4\}'


Note that this will only match all lines with 4 or more consecutive alphabetic characters. who can, depending on the configuration, return lines with text in which would match this besides the username...
User is offlineProfile CardPM
+Quote Post

NoobKnight

RE: Basic Command Line In Unix

25 Sep, 2009 - 01:38 PM
Post #3

New D.I.C Head
*

Joined: 14 Jul, 2009
Posts: 45



Thanked: 4 times
My Contributions
This works: who -u | awk '{print $1}' | grep "....."

Here is a live example


xxxxxx: who -u
matthewm ttyp1 Sep 25 07:37 8:50 2807
montem ttyp2 Sep 25 08:10 . 4716
chuckp ttyp4 Sep 25 08:25 2:12 6244
chuckp ttyp5 Sep 25 08:26 8:01 6346
danl ttyp6 Sep 25 08:28 6:32 6487
danl ttyp7 Sep 25 08:29 2:31 6563
timn ttyp8 Sep 25 08:57 6:43 8760
danl ttyp10 Sep 25 09:19 0:06 10492
danl ttyp11 Sep 25 09:20 0:07 10745
danl ttyp12 Sep 25 11:23 3:12 11031
johng ttyp13 Sep 25 10:01 5:36 407
danl ttyp14 Sep 25 11:25 2:56 11195
billc ttyp15 Sep 25 14:25 2:02 21060
tracyt ttyp16 Sep 25 15:00 0:06 22814
montem ttyp24 Jun 4 11:05 old 10953


Notice it doesn't select the people with only 4 chars in their logname.
xxxxxx: who -u | awk '{print $1}' | grep "....."
matthewm
montem
chuckp
chuckp
johng
billc
tracyt
montem

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 01:27PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month