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

Discussion in 'Scripting & Programming' started by zimbo, Mar 10, 2008.

  1. zimbo
    Honorary Member

    zimbo Petabyte Poster

    5,215
    99
    181
    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!!! :biggrin 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	
     
    Certifications: B.Sc, MCDST & MCSA
    WIP: M.Sc - Computer Forensics
  2. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    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.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  3. zimbo
    Honorary Member

    zimbo Petabyte Poster

    5,215
    99
    181
    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?
     
    Certifications: B.Sc, MCDST & MCSA
    WIP: M.Sc - Computer Forensics
  4. Mathematix

    Mathematix Megabyte Poster

    969
    35
    74
    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? :blink
     
    Certifications: BSc(Hons) Comp Sci, BCS Award of Merit
    WIP: Not doing certs. Computer geek.
  5. zimbo
    Honorary Member

    zimbo Petabyte Poster

    5,215
    99
    181
    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. 8)

    What you doing at 1am.. im writing a paper on VLANs - oh and i do have a drinking life!!! :biggrin
     
    Certifications: B.Sc, MCDST & MCSA
    WIP: M.Sc - Computer Forensics
  6. dmarsh
    Honorary Member 500 Likes Award

    dmarsh Petabyte Poster

    4,305
    503
    259
    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...
     
  7. Mathematix

    Mathematix Megabyte Poster

    969
    35
    74
    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&#37; 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.
     
    Certifications: BSc(Hons) Comp Sci, BCS Award of Merit
    WIP: Not doing certs. Computer geek.
  8. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    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.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  9. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,624
    117
    224
    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.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  10. zimbo
    Honorary Member

    zimbo Petabyte Poster

    5,215
    99
    181
    Alright thanks harry! 8)
     
    Certifications: B.Sc, MCDST & MCSA
    WIP: M.Sc - Computer Forensics

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.