Summary using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Summary using awk
# 15  
Old 01-14-2010
okay,now i seem to have a problem with the search command which i used.

Code:
Code:
echo -n "Title:"
read Title  
echo -n "Author:"
read Author
price_check=`grep $Title fruit | grep $Author | awk -F":" '
if [ "$price_check"="$Author" ] ; then
  echo "book exist"
else
 echo " Book does not exist"
fi
{print $3}'

`

Code:
Code:
Persia:42:John      ---database
France:50:Mabel 
Persia:50:Rach
Germany:60:John

for example, the user is to input title as "Persia" and "Author" as John. i will then use grep to search for lines which contain the title, then pipe it into another grep command which will then search for author based on the row available, then after that print $3 which is the name of the author.

So if i were to type in "rrrr" for title and "aaaa" for author, the value of price_check="" right? as there is not such existing data inside.


but for some reason, when i did a check on it, it does not seem to work. when i input data which is not in the database, it still displays the message "book exist" instead of telling me "book does not exist". Could you tell me the reason why.

Last edited by zaxxon; 01-14-2010 at 09:07 AM.. Reason: you were already asked to use code tags - do so please!
# 16  
Old 01-14-2010
Quote:
awk -F":" '
if [ "$price_check"="$Author" ] ; then
echo "book exist"
else
echo " Book does not exist"
fi
{print $3}'

`


what are you doing??!!!SmilieSmilie you are mixing awk with shell commands together

Note:- you can't use echo or other shell command inside awk like you did in above

you need to read more tutorial about awk....

# 17  
Old 01-14-2010
So how am i able to do a search with this two data to check if it is in the correct row?

---------- Post updated at 09:19 PM ---------- Previous update was at 08:46 PM ----------

Code:
echo -n "Title:"
read Title  
echo -n "Author:"
read Author
#awk -F":" '{print $1 }' fruit
awk  '{if ($1==$Title && $3==$Author) print $3 } ' fruit

i tried using this but nothing was printed. AM i using the if statement wrongly?
# 18  
Old 01-14-2010
Code:
awk  -F: '{if ($1=='$Title' && $3=='$Author') print $3 } ' fruit

# 19  
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

it should at least have an output , but for some reason nothing is being displayed. i have tried putting "" around the $title and $Author , but it does not seem to work. When u tried running it, did it work for u?
# 20  
Old 01-14-2010
Code:
note the '$Title' and '$Author'

# 21  
Old 01-14-2010
@gregarion: You are not copying Ahmad's example properly. Look closely and you will discover 4 additional single quotes that you left out.
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