Computer Hope

Software => BSD, Linux, and Unix => Topic started by: Harlequin on May 15, 2006, 01:10:48 PM

Title: Another Linux problem. Please help me.
Post by: Harlequin on May 15, 2006, 01:10:48 PM
The problem is that follows:
Construct a program (Shell script), called VERIF that asks for a name and verifies if it appears in other file called LISTING

I dont know how begin with this problem....

HARLEQUIN.
Title: Re: Another Linux problem. Please help me.
Post by: Rob Pomeroy on May 15, 2006, 02:25:14 PM
man grep

man awk

Remember that all programs return an exit code which indicates their success or failure.

Good luck.
Title: Re: Another Linux problem. Please help me.
Post by: Harlequin on May 16, 2006, 08:12:55 AM
Ok. Thanks for this clue. I will try doing something in that sense...

And I will tell you...

HARLEQUIN
Title: Re: Another Linux problem. Please help me.
Post by: Rob Pomeroy on May 16, 2006, 08:21:11 AM
Actually, I should have said

info gawk

since the Texinfo page is much better than the man page, and the utility's proper name on Linux systems is usually "gawk" (Gnu awk).
Title: Re: Another Linux problem. Please help me.
Post by: Harlequin on May 16, 2006, 08:53:59 AM
I just done it!!

the code is like follows:

user@linux> //(this is the prompt)
user@linux> cat > LISTING
James
Edward
Jhon
Peter
Paul
user@linux> //(and the file that contains the names is ready)

Now comes the shell script:

echo -n "Write a name: "
read name
if (grep -c $name LISTING) then
           echo "This name exists in LISTING file."
else
           echo "This name doesn´t exist in LISTING file."
fi

And this runs so fine....
Thanks very much Robpomeroy.... You have saved my life...
HARLEQUIN
Title: Re: Another Linux problem. Please help me.
Post by: Rob Pomeroy on May 16, 2006, 09:14:20 AM
Well done!