Summary using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Summary using awk
# 22  
Old 01-14-2010
Code:
echo -n "Title:"
read Title  
echo -n "Author:"
read Author

price_check=`awk  -F: '{if ($1=='$Title' && $3=='$Author') print $3 } ' fruit`
echo $price_check

sorry , when i copied the post before, i took it from another text page which i was using to test.

but yes, even when i use ahmad code, and input Persia into $Title and John for $Title , nothing seem to be happening when it suppose to echo out what $price_check is.
# 23  
Old 01-14-2010
use this:-

Code:
while true
do
echo -n "Title = "
read Title
echo -n "Author = "
read Author
if test nawk -F: '/'$Title'/ &&/'$Author'/' infile.txt &>/dev/null
then
echo $Author
else
echo "Book Does not exist"
fi
done

SmilieSmilieSmilie
# 24  
Old 01-14-2010
okay, i tested it out. For $Title i used Persia , for $Author , i used John. It is located inside the database. but when i ran it, the output was "book does not exist".

For the infile.txt , i should change this to the database file right? sorry, im not very clear on nawk.
# 25  
Old 01-14-2010
strange it work with me.
try below

Code:
while true
do
echo -n "Title = "
read Title
echo -n "Author = "
read Author
if grep $Title database.txt | grep $Author  &>/dev/null
then
echo $Author
else
echo "Book Does not exist"
fi
done



---------- Post updated at 17:02 ---------- Previous update was at 16:56 ----------

or try this :-

Code:
while true
do
echo -n "Title = "
read Title
echo -n "Author = "
read Author
nawk -F: '/'$Title'/ &&/'$Author'/' infile.txt &>/dev/null
if [ $? -eq 0 ]
then
echo $Author
else
echo "Book Does not exist"
fi
done


Last edited by ahmad.diab; 01-14-2010 at 11:19 AM..
# 26  
Old 01-14-2010
wow, it worked.thanks dude.

Code:
while true
do
echo -n "Title = "
read Title
echo -n "Author = "
read Author
if grep $Title database.txt | grep $Author  &>/dev/null
then
echo $Author
else
echo "Book Does not exist"
fi
done

Code:
&>/dev/null

what does this mean? and how come we are unable to use the command
Code:
awk -F":" '{print $3}'`

Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Files summary using awk based on index key

Hello , I have several files which are looking similar to : file01.txt keyA001 350 X string001 value001 keyA001 450 X string002 value007 keyA001 454 X string002 value004 keyA001 500 X string003 value005 keyA001 255 X string004 value006 keyA001 388 X string005 value008 keyA001 1278 X... (4 Replies)
Discussion started by: alex2005
4 Replies

2. Shell Programming and Scripting

Generating summary data (use awk?)

I have a data file similar to this (but many millions of lines long). You can assume that it is totally unsorted but has no duplicate rows. Date ,Tool_Type ,Tool_ID ,Time_Used 3/13/2014,Screwdriver,Screwdriver02, 6 3/13/2014,Screwdriver,Screwdriver02,20... (2 Replies)
Discussion started by: Michael Stora
2 Replies

3. Shell Programming and Scripting

Using awk to create a summary of a structured file

I am trying to use awk to create a summary of a structured file. Here is what it looks like: (random text) H1 H2 H3 H4 44 78 99 30 31 -- 32 21 12 33 55 21 I'd like to be able to specify a column, say H2, and then have information about that column printed. ... (4 Replies)
Discussion started by: afulldevnull
4 Replies

4. Shell Programming and Scripting

summary line help

$ cat file a:12:56:12 b:23:12:23 d:32:24:12 c:90:12:24 required output: a:12:56:12 b:23:12:23 d:32:24:12 c:90:12:24 t:157:104:71 t line is the total line, which will be the last line in the output. Please help. I tried this: (4 Replies)
Discussion started by: uwork72
4 Replies

5. UNIX for Dummies Questions & Answers

Directory Summary Command

Is there a unix command to provides the number of files in a directory? (2 Replies)
Discussion started by: rbarlow
2 Replies

6. UNIX for Dummies Questions & Answers

System Summary Tools

Are there any system sumary tools for Linux? What are some good ones for Solaris and HP-Ux? (2 Replies)
Discussion started by: vader
2 Replies
Login or Register to Ask a Question