Need help with a really basic assignment, probably gonna take you 5 mins to do.but it worse 7% to me


 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Need help with a really basic assignment, probably gonna take you 5 mins to do.but it worse 7% to me
# 8  
Old 04-16-2012
I can't do your assignment for you. I've given you all the pieces and told you where to find other things.

Try writing out pseudo-code which does what you want, then deciding what shell code to use for each bit of pseudocode. If that gives you trouble, we can help.

Try typing things into your shell and seeing if they work. If you get stuck, ctrl-c out. If you have trouble, ask specific questions.

But you can't just hand us an assignment and say "write code for me please".

Last edited by Corona688; 04-16-2012 at 03:53 PM..
# 9  
Old 04-16-2012
Quote:
Originally Posted by Corona688
I can't do your assignment for you. I've given you all the pieces and told you where to find other things.

Try writing out pseudo-code which does what you want, then deciding what shell code to use for each bit of pseudocode.

Try typing things into your shell and seeing if they work. If you get stuck, ctrl-c out.

Have you read any of the manual pages I suggested?
for now, all i need to know is the ideas or pieces of the 2nd question..
# 10  
Old 04-17-2012
I think you are more interested in getting the job done than gaining knowledge
What Corona688 has mentioned above is very useful info, you should take some time to learn

Anyways, here you go..... and it didn't take 5 mins, took longer than that

Code:
 
#!/bin/ksh
#The user's username and the absolute path of the login directory
echo "Your User Name is : $USER"
echo "Your home directory is : $HOME"
#The calendar of 2012
echo "Calendar for 2012 : "
cal 2012
#The total number of files and subdirectories in your login directory
filecount=`ls -l | grep '^-' | wc -l`
echo "Total No. of files in your $HOME directory : $filecount"
dircount=`ls -l | grep '^d' | wc -l`
echo "Total No. of subdirectories in your $HOME directory : $dircount"
#Accept an input of a positive number N that is not greater than 45 (using the read command), and display the first N lines of the contents of Rail-Stations.txt.
echo "Input no. of lines to read from Rail-Stations.txt"
read N
if [ $N -gt 0 ] && [ $N -le 45 ]
then
 head -$N Rail-Stations.txt
else
 echo "$N is either -ve or greater than 45"
fi
 
 
#The long listing of the directory specified by the first command line argument, sorted in reversed alphabetic order.
#If the second command line argument is provided, all the above output will be redirected to the file specified by the second argument. If the second argument is not provided, the above output should be displayed on the screen.
if [ $# -eq 2 ]
then
ls -l *$1* | sort -r > $2
elif [ $# -eq 1 ]
then
ls -l *$1* | sort -r
fi
#Accept the input of a series of lower case alphabetic letters one at a time. The input ends with a 0. Find and display the first letter in alphabetic order and the count of total number of valid input letters
 
Reply=Y
while [ $Reply == 'Y' ] || [ $Reply == 'y' ]
do
        echo "input a series of lower case alphabetic texts one at a time"
        text=a
        >tmp
        until [[ $text = "0" ]]
        do
                read text
                if [ $text == '0' ]
                then
                        break
                fi
                if [ `echo $text | grep '[a-z]'` ]
                then
                        echo $text >> tmp
                else
                        echo "invalid letter"
                fi
        done
echo "first letter"
sort tmp | head -1
echo "count"
wc -l tmp | awk '{print $1}'
 
#Before exit, ask user to confirm by entering a “Y” (“y”) or “N” (“n”). If confirmed, then exit, otherwise, return to the menu
#I am not sure what you mean by menu here, i think there is no point in repeating entire program so just repeating the 2nd taks you mentioned
 
        echo "Want to repeat (y/n) ?"
        read Reply
        if [ $Reply == 'n' ] || [ $Reply == 'N' ]
        then
                exit 0
        fi
done

Njoy!! Smilie
This User Gave Thanks to sam05121988 For This Post:
# 11  
Old 04-17-2012
Quote:
Originally Posted by sam05121988
I think you are more interested in getting the job done than gaining knowledge
What Corona688 has mentioned above is very useful info, you should take some time to learn

Anyways, here you go..... and it didn't take 5 mins, took longer than that

Code:
 
#!/bin/ksh
#The user's username and the absolute path of the login directory
echo "Your User Name is : $USER"
echo "Your home directory is : $HOME"
#The calendar of 2012
echo "Calendar for 2012 : "
cal 2012
#The total number of files and subdirectories in your login directory
filecount=`ls -l | grep '^-' | wc -l`
echo "Total No. of files in your $HOME directory : $filecount"
dircount=`ls -l | grep '^d' | wc -l`
echo "Total No. of subdirectories in your $HOME directory : $dircount"
#Accept an input of a positive number N that is not greater than 45 (using the read command), and display the first N lines of the contents of Rail-Stations.txt.
echo "Input no. of lines to read from Rail-Stations.txt"
read N
if [ $N -gt 0 ] && [ $N -le 45 ]
then
 head -$N Rail-Stations.txt
else
 echo "$N is either -ve or greater than 45"
fi
 
 
#The long listing of the directory specified by the first command line argument, sorted in reversed alphabetic order.
#If the second command line argument is provided, all the above output will be redirected to the file specified by the second argument. If the second argument is not provided, the above output should be displayed on the screen.
if [ $# -eq 2 ]
then
ls -l *$1* | sort -r > $2
elif [ $# -eq 1 ]
then
ls -l *$1* | sort -r
fi
#Accept the input of a series of lower case alphabetic letters one at a time. The input ends with a 0. Find and display the first letter in alphabetic order and the count of total number of valid input letters
 
Reply=Y
while [ $Reply == 'Y' ] || [ $Reply == 'y' ]
do
        echo "input a series of lower case alphabetic texts one at a time"
        text=a
        >tmp
        until [[ $text = "0" ]]
        do
                read text
                if [ $text == '0' ]
                then
                        break
                fi
                if [ `echo $text | grep '[a-z]'` ]
                then
                        echo $text >> tmp
                else
                        echo "invalid letter"
                fi
        done
echo "first letter"
sort tmp | head -1
echo "count"
wc -l tmp | awk '{print $1}'
 
#Before exit, ask user to confirm by entering a “Y” (“y”) or “N” (“n”). If confirmed, then exit, otherwise, return to the menu
#I am not sure what you mean by menu here, i think there is no point in repeating entire program so just repeating the 2nd taks you mentioned
 
        echo "Want to repeat (y/n) ?"
        read Reply
        if [ $Reply == 'n' ] || [ $Reply == 'N' ]
        then
                exit 0
        fi
done

Njoy!! Smilie
really really thank you! your code is prefect!....

im learning the knowledge that i dont know in this code... anyway... thanks very much!Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep last 5 mins from logs

Hi, system date format Thu Jun 13 12:55:18 EDT 2019 My log date format 09.148.192.60 - - "GET /akamai/sureroute-test-object.html HTTP/1.1" 404 231 can someone please help me, how to get last 5mins of logs please ? I need the command Please wrap your samples/codes in CODE TAGS,... (3 Replies)
Discussion started by: scazed
3 Replies

2. Shell Programming and Scripting

Need logs 5 mins old

I need 5 mins old logs to be dumped into a a new file. The date formats in the two log files are Can you suggect for both formats ? bash-3.2$ uname -a SunOS myserver 5.10 Generic_150400-26 sun4v sparc sun4v ---------- Post updated 05-04-16 at 12:24 AM ---------- Previous update was... (2 Replies)
Discussion started by: mohtashims
2 Replies

3. Shell Programming and Scripting

How to check if there is a file in the last 10 mins?

I have a script that runs every hour from the crontab (see the settings of the crontab below) (15 mins past the hour) 15 * * * * /home/usr/usr1/ProvAll This script saves two files in the following format now=`/bin/date '+%Y%m%d.%H%M%S'` file1.$now (for example) file1.20140722.031502... (12 Replies)
Discussion started by: knijjar
12 Replies

4. Red Hat

When is RHEL 7 Gonna Release?

When is RHEL 7 Gonna Release and When will the Exam Will be Conducted Any one have idea ? :mad: (2 Replies)
Discussion started by: babinlonston
2 Replies

5. Shell Programming and Scripting

tail for 15 mins

Hi, I want to write a script which will tail a particular file for 15 mins and then sleep for 10 mins and again tail for 15 mins. This cycle will go on for a limited period of time. How can i ensure that tail command will run for 15 mins before calling sleep command Thanks (6 Replies)
Discussion started by: @bhi
6 Replies

6. UNIX for Dummies Questions & Answers

files created within last 10 mins

Any simple 1 liners to check a directory to see if a file was created within the last 10 mins? (5 Replies)
Discussion started by: frustrated1
5 Replies
Login or Register to Ask a Question