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:
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!
You need to quote your arguments (and check how you spell "argument", wink wink) -- that should solve several of your problems.
Single quotes will prevent the expansion of $2 into its value; you are then grepping literally for (end of line) 2 which will never match. (Remember $ means end of line in regular expressions.) So don't use single quotes around a variable.
Things get tricky when you want to use both single quotes and double quotes, but you can even mix them in the same string. So to grep for $2 at end of line you could do something like
That's $2 in double quotes, and $ in single quotes, without any space or anything in between. (Next week, we will look at double quotes in single quotes and single quotes in double quotes in the same string.)
What's with the perl? This is a shell script, you'd run it with sh, not perl (although I guess perl is always Doing What You Mean and will actually run sh for you if it sees that you are giving it a shell script; but that sounds rather fragile for you to rely on).
Thank you so much for your reply. Sorry about the spelling!
To check the last name (input is the first letter) this worked!:
grep '^'"$2" dirInfo
One of my biggest questions is why the grep wont work for a string such as (123)456-7899. I get the syntax error near unexpected token `(' error.
-r
-c
-p
these are my only current problems. Two of them are with the area code/phone number so if I can figure out one than the other should be somewhat simple. I will continue to work on it but if anyone has any suggestions I would greatly appreciate them, thanks.
It seems as though its treating this phone number differently than a name?
it is Bash (your shell), not your script, that is complaining about the brackets. try
bash will parse the command line before it sends it to the script. To bash any expression in () is to be run in a sub-shell.
it is Bash (your shell), not your script, that is complaining about the brackets. try
bash will parse the command line before it sends it to the script. To bash any expression in () is to be run in a sub-shell.
WOW thank you so much! Is there any way to edit it in my code so I dont have to put the quotation marks in the input?
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)
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)
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)
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)
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)
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)
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)
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)
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)