Hello and welcome to CertForums.co.uk, here we host free active certification forums with links to the best free resources for Microsoft's MCSA MCSE MCDBA Cisco's CCNA CCDA and CCNP, and CompTIA's A+ Network+ i-NET+ and Security+ certifications in the UK. If you wish to post or use other advanced features you will need to register first. Registration is absolutely free and takes only a few minutes to complete so sign up today!

If you have any problems with the registration process or your account login, please contact support

Go Back   CertForums > Computing Support Forums > Programming & Scripting
Home Forums Register Search Today's Posts Mark Forums Read

Nearly Finished my Shell Program!!! Some Help Please!

Post New ThreadReply
 
Thread Tools Display Modes
  #1  
Old 10-Mar-2008, 03:27 PM
zimbo's Avatar
zimbo zimbo is offline
Resident Greek Mafia Boss
Posts: 5,218
Points: 1395 zimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 points
Power: 71
None
Join Date: 10 Jul 2005
Location: London & Cyprus
Age: 23
Certifications: MCDST & MCSA
WIP: B.Sc Computer Networks
Nearly Finished my Shell Program!!! Some Help Please!

Well if you guys been wondering where i been the past month.. been hitting the books.. between creating HTTP Servers in Java and Shell programming im going nuts!!! Anyway this is the 90% completed version of my Shell Program. I would like some help so i can get a 1st instead of a 2:1 which Im really wanting cause we had to teach ourselves shell programming so i think this is a real good effort for my first time.

The two things i need help with are:

1. Suppose I have a text file - could someone help me please with the code to find Proper Nouns (eg words that start with capital letters but not the start of setences for example New York, Tom, France etc) I been trying to figure it out and to no avail so please if someone could help me i would greatly appreciate it.

2. We need to do something special and the tutor suggests we encrypt text and decrypt it. How would you go about this? Suppose i have a text file and i press 11 to encrpyt and 12 to decrypt, again I have tried to find reading material on this and i cant find nothing. Anyone got any information to help me please?

I know some of you are thinking "Cheeky sod he wants us to do his homework" but look at what i did on my own in 1 month of learning shell - plus those of you who know me that im not like that anyway.

Anyway thanks in advance for the help if you can and here is what i did so far:

Code:
echo
echo
echo
echo "**********The GeekEasy Text Editor*******"
echo

echo "Please enter the file name you wish to edit: "
read FileName
echo

option=1
while [ $option -ne 10 ]
do
echo
echo
echo "1) Count Letters,Words and Lines"
echo "2) Count Specfic Letters"
echo "3) Count Specfic Words"
echo "4) Sentence Count" 
echo "5) List Proper Nouns"
echo "6) Change Text File"
echo "7) Insert Lines into Text"
echo "8) Amend Text"
echo "9) List the Text"
echo "10) Exit the System"
echo

echo "Please enter your choice: "
read option
echo

case $option
in
	1)echo
	echo "Word count is: "
	cat $FileName |wc -w
	echo
	echo "Line Count is: "
	cat $FileName |wc -l
	echo
	echo "Character count is: "
	cat $FileName |wc -m;;
	
	2)echo "Enter the letter to find:"
	read str
	echo
	tr -d $str < $FileName | wc -m > temp1
	wc -m < $FileName > temp2
	read num1 < temp1
	read num2 < temp2
	sum=$((num2-num1))
	echo "There are" ${sum} $str "'s";;

	3)echo "Enter a word to count"
	read str
	echo
	echo "The number times that word appears is:"
	sed "s/$str/$str\n/g" $FileName | grep $str | wc -l;;

	4)uc=.,!?""
	i=`tr -d [$uc] < $FileName | wc -c`      	 
	j=`cat $FileName | wc -c`			
	k=`expr $j - $i`                       		  
      	echo
	echo There are "$k" sentences in the file
	echo;;

	5)echo "Under Construction";;

	6)echo "Please Enter the File path you wish to change to:"
	echo /gg226/CW4/	
	read FileName;;

	7)echo "Enter the line number you wish to edit:"
	read numline
	echo "Enter new text you wish to appear:"
	read newtext
	sed "$numline i\ $newtext " $FileName>temp3
	mv temp3 $FileName;;

	8)echo "Enter the old word"
	read old
	echo "Enter the new word"
	read new
	cat $FileName | sed s/$old/$new/g > temp1
	mv temp1 $FileName;;

	9)echo
	 cat $FileName;;

	10)echo "Program Exited";;
	*)echo "Error!";;
esac
done




 
Reply With Quote
  #2  
Old 10-Mar-2008, 10:14 PM
hbroomhall hbroomhall is online now
Premium Member
Posts: 6,222
Points: 2130 hbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 points
Power: 89
None
Join Date: 08 Sep 2005
Location: Tunbridge Wells, Kent
Certifications: ECDL A+ Network+ i-Net+
WIP: Server+
OK - three (three?) things.

0) Put a hashbang at the start of any script file.

1) Assumptions - a sentence will only start at the beginning of a line when it is the start of a paragraph. This is the bit that is fuzzy - are there any rules about this you have been given? Otherwise a sentence beginning will match "$us[:space:]+[:Upper:]". Which means that you can find other instances of [:Upper:].
Edit: This of course won't find sentences that start "Tom said.....". Whether this matters depends on the rules you have been given.

2) Do "man crypt".

Harry.


Last edited by hbroomhall : 10-Mar-2008 at 10:17 PM.
 
Reply With Quote
  #3  
Old 11-Mar-2008, 12:05 AM
zimbo's Avatar
zimbo zimbo is offline
Resident Greek Mafia Boss
Posts: 5,218
Points: 1395 zimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 points
Power: 71
None
Join Date: 10 Jul 2005
Location: London & Cyprus
Age: 23
Certifications: MCDST & MCSA
WIP: B.Sc Computer Networks
Harry could you reword number 0 and 2 please? There are no rules only thing we are told is:

List Proper names appearing in the text (In English they begin with a capital letter - but so does the first word of a sentence.)

Reading up the man page! Thanks!

Edit: After reading the man page.. im assuming im going to have to write this in C or Perl?





Last edited by zimbo : 11-Mar-2008 at 12:13 AM.
 
Reply With Quote
  #4  
Old 11-Mar-2008, 01:22 AM
Mathematix's Avatar
Mathematix Mathematix is offline
Longterm Member
Posts: 803
Points: 1124 Mathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 points
Power: 24
None
Join Date: 09 Mar 2006
Location: London
Certifications: BSc(Hons) Comp Sci, BCS Award of Merit
WIP: Not doing certs. Computer geek.
Slap me for this if you wish, but why is a 1st resting on this sole script, and shouldn't it be a doddle to complete if you are going to get such a degree?


 
Reply With Quote
  #5  
Old 11-Mar-2008, 01:31 AM
zimbo's Avatar
zimbo zimbo is offline
Resident Greek Mafia Boss
Posts: 5,218
Points: 1395 zimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 points
Power: 71
None
Join Date: 10 Jul 2005
Location: London & Cyprus
Age: 23
Certifications: MCDST & MCSA
WIP: B.Sc Computer Networks
LOL if u look back.. you will see last year i kinda ace'd all 6 modules i mean 99% and above so im kind of a perfectionist. Ok this project only counts for 30% of my grade but i have implemented 11 out of the 12 objectives and i want to try do all 12 and the "extra" one.. yea im a geek and im proud of it - some come to uni to pass.. sorry mate not me.. i came to uni to get the best grade i can with all the help i can find - i wont cheat but ill use every resource i can including this forum mate cause i know there is plenty of experts on here to help me. What would you do? BTW my degree does ride on 1st's cause im trying to get into Kings College in London which require a 1st Class degree to start off with for postgrad.

What you doing at 1am.. im writing a paper on VLANs - oh and i do have a drinking life!!!




 
Reply With Quote
  #6  
Old 11-Mar-2008, 08:41 AM
dmarsh26's Avatar
dmarsh26 dmarsh26 is online now
Lifetime Member
Posts: 1,031
Points: 1860 dmarsh26 has over 1500 pointsdmarsh26 has over 1500 pointsdmarsh26 has over 1500 pointsdmarsh26 has over 1500 pointsdmarsh26 has over 1500 pointsdmarsh26 has over 1500 pointsdmarsh26 has over 1500 pointsdmarsh26 has over 1500 pointsdmarsh26 has over 1500 pointsdmarsh26 has over 1500 pointsdmarsh26 has over 1500 points
Power: 31
None
Join Date: 24 May 2007
Location: Hampshire
Age: 34
Certifications: One or two...
WIP: Girlfriend+
Sorry Zimbo but I think we should have a forum rule for not posting your homework, assignment, thesis etc !

God knows we gave Kobem a hard enough time about it !

Maths right if you deserve a first you will get one without having to resort to getting help every step of the way.

Nothing wrong with asking questions but I think this is a little too close to 'please help me with my homework' for me.

By the way I did all my own homework and got a 2:1. Some people pestered the lecturers every 2 minutes for every tip and clue and extra bit of help and a couple of them got firsts, not on merit by my mind...


 
Reply With Quote
  #7  
Old 11-Mar-2008, 01:24 PM
Mathematix's Avatar
Mathematix Mathematix is offline
Longterm Member
Posts: 803
Points: 1124 Mathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 pointsMathematix has over 1000 points
Power: 24
None
Join Date: 09 Mar 2006
Location: London
Certifications: BSc(Hons) Comp Sci, BCS Award of Merit
WIP: Not doing certs. Computer geek.
dmarsh said it all already.

Got a prize with my degree and interest from Cambridge to read Part III of the Mathematical Tripos during my degree, all from work off my own back without external help... literally! Right now I work at a studio where all programmers are ranked in the top 25% on the planet.

When I was looking for a university I was interviewed by King's and trust me, if you can't handle this script you will sink like a stone on their Masters programme. I know another guy who got a First for his games programming degree and he was sweating it on the MSc Advanced Computing there.

Just think you should know.



Last edited by Mathematix : 11-Mar-2008 at 01:28 PM.
 
Reply With Quote
  #8  
Old 11-Mar-2008, 04:43 PM
hbroomhall hbroomhall is online now
Premium Member
Posts: 6,222
Points: 2130 hbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 points
Power: 89
None
Join Date: 08 Sep 2005
Location: Tunbridge Wells, Kent
Certifications: ECDL A+ Network+ i-Net+
WIP: Server+
Quote:
Originally Posted by zimbo View Post
Harry could you reword number 0 and 2 please?
I'll do this in two parts.
First my point 0.

How are you running these scripts? Something like:
"sh mywhizzoscript"?

While this works well it would be nice to make the script an executable. You do this by first marking it as executable with chmod. Then you add a line to the start often known as a 'hashbang'. Literaly - the characters "#!". This is followed by the full path to the executing shell.

This is the line from one of my scripts on a box I admin:
Code:
#!/usr/local/bin/bash
The #! pair acts as a 'magic number' and tells the shell to look at the rest of the line for the method of invoking the script. Other script languages work in exactly the same way - Perl, Ruby etc.

IMHO it is good practice to always put a hashbang on the start of every script.

Harry.

 
Reply With Quote
  #9  
Old 11-Mar-2008, 04:56 PM
hbroomhall hbroomhall is online now
Premium Member
Posts: 6,222
Points: 2130 hbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 pointshbroomhall has over 2000 points
Power: 89
None
Join Date: 08 Sep 2005
Location: Tunbridge Wells, Kent
Certifications: ECDL A+ Network+ i-Net+
WIP: Server+
Quote:
Originally Posted by zimbo View Post
Harry could you reword number 0 and 2 please?
Reading up the man page! Thanks!

Edit: After reading the man page.. im assuming im going to have to write this in C or Perl?
OK - point 2.

I meant for you to look at the man page for crypt(1), but I gather that this is missing on a lot of Linuxes. It is present on my FreeBSD box!

Alternatives would be pgp, and openssl.

Harry.

 
Reply With Quote
  #10  
Old 11-Mar-2008, 06:28 PM
zimbo's Avatar
zimbo zimbo is offline
Resident Greek Mafia Boss
Posts: 5,218
Points: 1395 zimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 pointszimbo has over 1000 points
Power: 71
None
Join Date: 10 Jul 2005
Location: London & Cyprus
Age: 23
Certifications: MCDST & MCSA
WIP: B.Sc Computer Networks
Alright thanks harry!




 
Reply With Quote
Post New ThreadReply Spread this thread: Submit this thread to digg Submit this thread to del.icio.us


Go Back   CertForums > Computing Support Forums > Programming & Scripting


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Anyone used this program? Tinus1959 Software 2 06-Mar-2008 02:21 PM
finished reading meyer's 6th edition. fish79 A+ 11 01-Mar-2008 04:41 PM
Program needed for file sync. nugget Software 6 29-Feb-2008 02:23 PM
Just Finished BIS @ Uni and searching for a job.. wilecoyote New Members Introduction 7 30-Jan-2008 01:21 PM
Exchange Management Shell Tips of the Day Mitzs Networking 0 30-Sep-2007 08:17 PM


All times are GMT. The time now is 10:01 PM.

Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
CertForums.co.uk (C) copyright 2003-2007 All Rights Reserved. Content published on CertForums.co.uk requires permission for reprint.
Hosted by Lunarpages