LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 12-01-2012, 05:03 AM   #1
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Awk query


Hi everyone,
I have a script with following lines:
Code:
grep " string " filename \
awk 'BEGIN{sum=0; cat1=0; cat2=0; cat3=0;}
{sum++}
/testval=0\.[^0]/{cat2++;}        
/testval=0\.0/{cat3++;}
END{cat1=sum-(cat2+cat3); print cat1, cat2, cat3;}'
Everything's fine, but I don't understand that what pattern it's searching in line marked in red? Is it summing up all testval value that are greater than 0.0 (i.e. 0.1, 0.2... and so on)? Or does it mean that take all values that begin with a 0 after decimal point?
Also what's difference between lines marked in red line marked in blue?

Last edited by shivaa; 12-01-2012 at 05:08 AM.
 
Old 12-01-2012, 05:09 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Wasn't this already discussed in your other thread?

Help understanding "awk" code

Especially this post (and the follow ups): post #7
 
1 members found this post helpful.
Old 12-01-2012, 05:20 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Original Poster
Rep: Reputation: 285Reputation: 285Reputation: 285
@druna: Yes, but a little query! in your answer you had mentioned following:
Quote:
Code:
/value=0\.[^0]/{cat2++;} increment cat2 if not value=0.0
[^0] -> all but a zero
I couldn't understand what your comment "all but a zero" saying? A carrot sign (^) means all values begginning with the character after it.. Am I right? Then it should consider all values which are 0.0<whatever>
Please correct me if I explained it wrong.
 
Old 12-01-2012, 05:27 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Quote:
Originally Posted by shivaa View Post
I couldn't understand what your comment "all but a zero" saying?
all but a zero In different wording -> everything except zero

Quote:
A carrot sign (^) means all values begginning with the character after it.. Am I right? Then it should consider all values which are 0.0<whatever>
That isn't correct. A carrot inside a range means not

Code:
^[0-9] -> A number at the beginning of the line,
[^0-9] -> Not a number,
^[^0-9] -> Not a number at the beginning of the line.
Have a look here: Regex Tutorial, Examples and Reference / Regular Expression Basic Syntax Reference
 
1 members found this post helpful.
Old 12-01-2012, 05:53 AM   #5
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Original Poster
Rep: Reputation: 285Reputation: 285Reputation: 285
Great! Thanks for making it clear.
 
  


Reply

Tags
awk


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
awk query jkeertir Linux - Newbie 3 01-17-2014 04:12 AM
Ghostdog74 | AWK Query lmedland Programming 4 08-17-2008 08:38 AM
awk query jkeertir Linux - Networking 3 04-07-2008 08:07 AM
awk program. a little query! indiancosmonaut Programming 7 07-05-2007 09:48 AM
help with mysql query: return nth rows in query hawarden Programming 2 07-31-2006 06:36 PM


All times are GMT -5. The time now is 01:19 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration