Summary using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Summary using awk
# 8  
Old 01-14-2010
Try:
Code:
sed "/$Title.*:.*$Author/d" fruit


Last edited by Scrutinizer; 01-14-2010 at 08:26 AM.. Reason: It was the other way around
# 9  
Old 01-14-2010
Hey ahmad, i tried it out. and instead of deleting the row which contained both $title and $author, instead it deleted the other information instead and left the rows which contained either $title or $author. For example

Code:
awk '/'$Title'/&&/'$Author'/{$0="" ; next}1' fruit > fruittemp
mv fruittemp fruit

$title = Persia , $Author = John

the original database was :
Code:
Persia:42:John
France:50:Mabel 
Persia:50:Rach
Germany:60:John

but after trying out the code, it came out :

Code:
Persia:42:John
Germany:60:John

any clue why?
# 10  
Old 01-14-2010
you can embed my solution to scrutinizer solution in one line as below:-

Code:
awk  '/'$Title'/&&/'$Author'/{$0="" ; next} $1=$1' FS=: OFS="\t\t" <(echo "Title:Price:Author") infile.txt

next:- go to next line.
1:- if (true) print.


SmilieSmilieSmilie

---------- Post updated at 13:09 ---------- Previous update was at 13:03 ----------

Quote:
Originally Posted by gregarion
Hey ahmad, i tried it out. and instead of deleting the row which contained both $title and $author, instead it deleted the other information instead and left the rows which contained either $title or $author. For example

Code:
awk '/'$Title'/&&/'$Author'/{$0="" ; next}1' fruit > fruittemp
mv fruittemp fruit

$title = Persia , $Author = John
the code did not make a mistake you did..

it is Title=Persia not title=Pertia SmilieSmilieSmilie
# 11  
Old 01-14-2010
Hey ahmad, okay i managed to realize why i got the problem. Just to comfirm :

Code:
'/'$Title'/&&/'$Author'/

this line is to state the pattern i.e. what it should it search for in each row and "&&" means that title AND author has to be present in that row right?

and

Code:
{$0="" ; next}1'

*this means that once you find a line which $title and $author is present, you are to empty the row? if both inputs are not found in a row, it will move on to the next row. and for the 1 , it is to state of the pattern is true, then the rows will be made "" =empty?

# 12  
Old 01-14-2010
Code:
when you find the row empty it then go to next line

in next line it will search again for title and authur if he didn't get it it will go to
 "1" which means print.

SmilieSmilieSmilieSmilie
# 13  
Old 01-14-2010
So as long as the row does not contain title and author , it will print the line out right? if it does, the $0="" will delete it?
# 14  
Old 01-14-2010
Quote:
Originally Posted by gregarion
So as long as the row does not contain title and author , it will print the line out right? if it does, the $0="" will delete it?
Finally you got it SmilieSmilieSmilieSmilie
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