Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Project with somewhat simple bourne shell cript.. Post 302185001 by Generic on Monday 14th of April 2008 02:24:57 AM
Old 04-14-2008
Project with somewhat simple bourne shell cript..

Right now if I have a file that has the following information (with : as the delimiter)

name :address :phone number

I need to be able to do the following commands:
-n search for a name
-p search for a phone number
-l search for a last name starting with a particular
-c find an area code
-a add a new record to the file
-r replace an entry with new data

An example of running the script would be :

perl ./phonebook -l A (-l is first arguement and A is second arguement)
perl ./phonebook -a Jones, Edward

I currently have:

Code:
#if there are no arguements (IE -r, -l, ect) than output the file
if [ $# -eq 0 ]
then
cat < dirInfo

#if the first arguement is -n, output any line that contains the 2nd argument (this WORKS, and if the name is the 2nd argument it will output the whole line of information)
elif [ "$1" = "-n" ]
then
grep $2 dirInfo

#I keep getting a "syntax error near unexpected token `('" error.  I figured I could use the grep for the phone number just like the name?  
#I have also tried something like grep '[0-9]\{3\}-[0-9]\{4\}'	but dont know how to compare with 2nd arguement.
elif [ "$1" == "-p" ]
then
grep $2 dirInfo

#I cant grep a variable? This seems to be one of the main things stopping me, I dont know how to incorporate the variable (their input) into grep.
elif [ "$1" == "-l" ]
then
grep '^$2' dirInfo

#As for finding an area code, I would assume thats very similar to finding the whole number, with a small edit of the code.
elif [ "$1" == "-c" ]
then

#Appending a name that they enter (arguement 2).  This does not work at all.
elif [ "$1" == "-a" ]
then
sed '$a\$2'

#=: command not found
elif [ "$1" == "-r" ]
then
echo "Enter the new name: "
read name
echo "Enter the new address: "
read address
echo "Enter the new phone number: "
read phonenumber
$line = grep $2 dirInfo
sed 's/$line/name, address, phonenumber/p' dirInfo
else
echo "not found."
fi

I know there are tons of problems :( I have been googling and reading "Unix The Ultimate Guide by Sumitabha Das" but am still in need of a lot of help. Any input is appreciated, thanks!
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Bourne shell script need help please ?

i have this assignment.. and i mad this script but there is something wrong with it.. if anyone can tell me.. watz going on... i would appreciate it.. tHnX in advance.. count=1 val=$2 op=$1 ans=0 if then if then while do ... (7 Replies)
Discussion started by: dezithug
7 Replies

2. Shell Programming and Scripting

simple bourne script

Hello There, I am trying to write this SIMPLE script in Bourne Shell but I keep on getting a blank response. Can you see what I am doing wrong? I am simply trying to take the day of the week from our system and when the teachers sign on I want them to see the message of the day, when they exe... (2 Replies)
Discussion started by: catbad
2 Replies

3. Shell Programming and Scripting

simple Bourne problem

Hi, I'm a newer for this languages, and I have a log file, which is something like this: 35.75.253.207 - - "GET /products/orgonizer/title.png HTTP/1.1" 200 1555 "-" "Mozilla 1.4" Now, I want to write a shell code to accoplish like ./XXX.sh -N n n is a number by user input, the code should... (5 Replies)
Discussion started by: pnxi
5 Replies

4. UNIX for Dummies Questions & Answers

Bourne-again shell

Hi guys !! well i'm still new in learning UNIX , and actually i'm still studying it by myself .. anyway, some people told me the Bourne-again shell is a good version of UNIX to work on , and i tried to download yesterday but i didn't know how to start it ...... the ReadMe file associated with... (3 Replies)
Discussion started by: mrsamer
3 Replies

5. Shell Programming and Scripting

I need to understand the differences between the bash shell and the Bourne shell

I do not claim to be an expert, but I have done things with scripts that whole teams of folks have said can not be done. Of course they should have said we do not have the intestinal fortitude to git-r-done. I have been using UNIX actually HPUX since 1992. Unfortunately my old computer died and... (7 Replies)
Discussion started by: awk_sed_hello
7 Replies

6. Shell Programming and Scripting

How to activate Korn Shell functionnalities in Bourne Shell

Hi All I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell. Some operations like calculation don't work : cat ${file1} | tail -$((${num1}-${num2})) > ${file2} Is it possible to activate Korn Shell... (3 Replies)
Discussion started by: madmat
3 Replies

7. Shell Programming and Scripting

Xapture Plsql Error from Unix Shell cript

Hi Friends, Need your help . I have a shell script which executes the plsql procedure proc_p1. I want to capture the error message when the procuder throws some error message. I codeed in the following way . But it shows Job Success. Kindly anyone give some better idea to over come this ... (2 Replies)
Discussion started by: imipsita.rath
2 Replies

8. Shell Programming and Scripting

Bourne/C shell help

Exercise Five Write a Bourne shell script which: • Professionalism: plan for this from the start. • Has one command line argument. • If the command line argument is a directory then the script should output the number of files in the directory. • If the command line argument is an ordinary... (2 Replies)
Discussion started by: moesom
2 Replies

9. Shell Programming and Scripting

Bourne shell & Korn shell

Could some one tell me the difference btw Bourne shell and the Kshell? Which is more flexible and reliable in terms of portability and efficiency. When i type the following command .. $ echo $SHELL yields me /bin/sh Does this tells me that I am in Bourne shell. If yes, how can i get... (6 Replies)
Discussion started by: bobby1015
6 Replies

10. Cybersecurity

'Shell Shock' vulnerability in Bourne shell

A severe vulnerability was discovered in Bourne shell. Just google for: bash vulnerability ... for more details. (5 Replies)
Discussion started by: Cochise
5 Replies
ZGREP(1)                                                      General Commands Manual                                                     ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 03:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy