LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-31-2007, 12:26 AM   #1
nadeemr
LQ Newbie
 
Registered: May 2007
Posts: 18

Rep: Reputation: 0
please help!


I have a couple of questions :
1.how do I write a small shell script called "biggest_uid.sh" that prints out the entry from the password file /etc/password with the largest uid?
I need to use the sort command

2. a small shell script 'usernames' that take letters as an argument and list all usernames matching the pattern?
I need to use grep

3. a small shell script 'count_users' that prints out the number of usernames that begin with each letter of the alphabet. The output should appear sorted from greatest to least occurrence.

please help!
thank you
 
Old 05-31-2007, 01:57 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

2 things:

1) Use a Subject that is clear. 'please help' doesn't tell us anything and a lot of readers won't even look at a thread that has a subject like this. 'Need help with my homework' would have been suitable......

2) This looks like homework, the LQ rules state that we don't do that for you. We are willing to help you if you get stuck with something, but we are not going to give you (all) the answers.
 
Old 05-31-2007, 02:33 AM   #3
Zmyrgel
Senior Member
 
Registered: Dec 2005
Location: Finland
Distribution: Slackware, CentOS, RHEL, OpenBSD
Posts: 1,006

Rep: Reputation: 37
Sounds like a school work to me, you should figure them out yourself but let me give some hints:

1) Script starts with #!/bin/sh and you should use cat and sort
2) Cat /etc/passwd file, use grep to find patterns for it. ^ means from beginning of file
3) Cat /etc/passwd file, sort to sort the output, unique to reduce duplicates etc.

Read the manual pages for above commands and that should be an easy task.
 
Old 05-31-2007, 06:08 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Pixellany's rules for getting help on homework:
  1. State up front that it is in fact homework
  2. Give some information on what has been studied--so that we know what you are supposed to already know.
  3. Show evidence that you have done something already--eg show your current attempt at the problem and what part is not working.
  4. For members: The sure clue on homework is one post with no follow-up....unless we hear from OP again, do nothing.

We ARE allowed to help you---the rules say that you should not expect it.
 
Old 05-31-2007, 06:33 AM   #5
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Man and info pages are the first step you should take when solving a problem like this; especially now because you know 1) what your goal is and 2) what tools you're intended to use (at least), read the appropriate man/info pages to get the information out. After you know the (basic) usage of the tools you can start thinking how to use them, to get the result. In this case I'm pretty sure all you really have to do is stop waiting for ready answers, read the manpages trough (or use search in them, which is very handy) and...well, given the problems are those you mentioned, you should know the answer by then.

Code:
man man
man cat
man grep
man sort
info cat
info grep
info sort
start off those..

EDIT: there are other places than just LQ where you can find relevant information (but not ready answers), one good place for shell script startup is linuxcommand.org which provides basic knowledge about shell commands and scripting.

Last edited by b0uncer; 05-31-2007 at 06:34 AM.
 
Old 05-31-2007, 06:53 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by nadeemr
1.how do I write a small shell script called "biggest_uid.sh" that prints out the entry from the password file /etc/password with the largest uid?
I need to use the sort
I will show you this one to give you an idea, since its homework. the rest you have to do them yourself. follow the advice the good people have given,, and post here again if you are stuck.
Code:
sort -n -t":" -k3 < /etc/passwd
the biggest uid is the last line. you can use tail to get the last line.See the man page of sort for explanation of those switches.
 
Old 05-31-2007, 08:59 AM   #7
nadeemr
LQ Newbie
 
Registered: May 2007
Posts: 18

Original Poster
Rep: Reputation: 0
ok thanx guys...
I will try getting the necessary information and post the codes here...if u can check them out afterwards to see if am missing something, that will be great!
 
Old 05-31-2007, 11:54 AM   #8
ethics
Senior Member
 
Registered: Apr 2005
Location: London
Distribution: Arch - Latest
Posts: 1,522

Rep: Reputation: 45
Quote:
Originally Posted by nadeemr
ok thanx guys...
I will try getting the necessary information and post the codes here...if u can check them out afterwards to see if am missing something, that will be great!
Surely the correct/incorrect execution of your scripts will tell you what you are missing. You'll also be able to see if you can refine them, or create a script that collates all the info etc.

Might impress the lecturer.
 
Old 06-03-2007, 12:37 PM   #9
nadeemr
LQ Newbie
 
Registered: May 2007
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by nadeemr
I have a couple of questions :
1.how do I write a small shell script called "biggest_uid.sh" that prints out the entry from the password file /etc/password with the largest uid?
I need to use the sort command

2. a small shell script 'usernames' that take letters as an argument and list all usernames matching the pattern?
I need to use grep

3. a small shell script 'count_users' that prints out the number of usernames that begin with each letter of the alphabet. The output should appear sorted from greatest to least occurrence.

please help!
thank you
3. a small shell script 'count_users' that prints out the number of usernames that begin with each letter of the alphabet. The output should appear sorted from greatest to least occurrence.

my script is as follows:
#!bin/bash
alphabet = "a b c d e"
count = 0
for letter in $alphabet
do
count = 'expr $count + 1'
echo = "letter $count is [$letter]"
done

am i missing something here?

Last edited by nadeemr; 06-03-2007 at 12:38 PM.
 
Old 06-03-2007, 12:48 PM   #10
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
What is your question? Are we supposed to be de-bugging this for you? If so, then you would have to tell us the errors you are getting

Quote:
count = 'expr $count + 1'
Suggest that you look up the difference between ' (hard quoting) and ` (The backtick) Hint: they give different results.

Quote:
[$letter]
What does this mean?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off




All times are GMT -5. The time now is 08:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration