I'm designing a script that will have to accept user input from the command line using the read command.
The problem is that I have to check the input which should be in the format of
<first name> <last name> <phone number (8 digits long)>
The input can also be
Just <first name>
Or just <last name>
Or <phone number>
I need a way to test this input before I pass it to grep with a text file that has stored names and phone numbers i.e
Stephen Smith:12345678
The user should be able to search using the first name, last name or the phone number for example a user types in Stephen, the entry in the text file should display.
The test should include that no numbers are in the first and last names and that the phone number does not start with a 0 (zero). These are just errors checks which will display a message to user if they have entered it in incorrectly.
Any help would be appreciated.
Thanks :-)
Here is some code that I've done
*Code is incomplete and just tries to establish what sort of input the user made, so now I just need to test it and if it passes then I can pass it to grep to look it up in the texfile. If its not in the textfile I will then add it.
hi
is there any reason that you need to check that the names do not contain numbers and stuffs like that??
i could just use grep to search against your telephone directory using the search term, and simply flag out to user "Entry not found" , if it does not match what user types in.
If need be, i can just provide a simple help message telling the user what he can or cannot enter as a search term when the grep fails..
It would be simpler this way..well at least to me...
No you can take the input as is. I read your post as being, "need to check input before passing to grep" Hence that code. (Checking for non printable characters)
Other wise don't bother and just let grep do its thing.
A though just crossed my tired mind... you could use tr to delete any non printable characters first. just a thought.
Hi All,
I am facing a problem while checking for existence of file over ssh !
Basically, i want to ssh and check if file exists.. If file exists return 1. If file does not exits return 0 (or any value)
I am using the below code
file_avail=`ssh username@host "if ]; then exit 1;... (10 Replies)
Hello Everyone,
I have a process that should be always running. Unfortunately, this process is getting down almost every 10 minutes. I want to make a script that verify the state of this process: If the process is up, the script shouldn't do nothing and if it's down he should run it.
Can... (3 Replies)
I am currently wrapping up a assignment for one of my classes. I need help writing some error checking logic. The problems I am having are:
keeping track of the records I have deleted and reported it back using echo.
I have no idea how to do this.
ensuring that line numbers fall... (1 Reply)
This is the source code:
#include <pwd.h>
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
struct passwd *user;
char login="alex", password="qwertyuiop";
if ((user= getpwnam(login)) == NULL)
cout << "No such user\n";
else if... (24 Replies)
Hey guys i am facing a problem in my sql statement. I am trying to check if there is such a value in the database.
Code:
string NewMovie = "ww";
string queryText ;
queryText = "Select * from movie_info WHERE movie_title = '"+ NewTitle +"'";
... (1 Reply)
Hello all
I am having problems using a bash script to read the input from the user and checking that its a valid number. I only want the user to input a maximum of a 3 number string (321 , 521 , 871 etc.). Anything longer or that includes a chararcter or symbol will display an error message.
... (8 Replies)
Hi All,
I have a written a scell script which checks the existence of a directory. The dierctory name is read from property file. Though the dierctory exists but it says - it does not exist--
Find my code below --
#! /bin/ksh
#Tibco Properties file is inclusion
.... (5 Replies)
Hi everyone,
I am writing a script. As a part of this script, I wanted to check the space of few mounts, If the space usage percentage of the mount crosses over a certain limit then i wanted to display a warning message. The following is the command
df -k | awk ' { if (($6 == "/export/temp")... (4 Replies)
Hi,
I would like to know given executing a file with inputs, I would like to know when does it terminate /abort abnormally.
I tried to append an echo $? after executing my program which is in C. However, there is nothing..It shows 0 even though the program actually exit.
my command is... (1 Reply)
I am creating a script that will automatically use sftp to connect to a site and download a file, extract the tar and then delete the tar file once completed.
What I am stuck on is the error checking for this process.
Here is the code so far:
Now this works for me as is, but i need... (0 Replies)