Solved

AWK: number of lines returned ?

Posted on 2007-11-20
5
1,043 Views
Last Modified: 2013-12-26
How do you get the number of lines returned by an
AWK search, that is the number of matches that it
has found ?
0
Comment
Question by:pillmill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 20322494
awk | wc -l
0
 

Author Comment

by:pillmill
ID: 20322598
Thanks.
Can I assign this result to a variable ?
(I'm using Bourne shell)

I want to test if there is more than match found.
For example,

f= [ awk | wc -l  ]

if f > 2 then ...
0
 
LVL 48

Expert Comment

by:Tintin
ID: 20322683
Why awk and not grep?

if [ `grep -c string file` -gt 2 ]
then
    echo "More than 2 matches"
fi
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
ID: 20326642
f=`awk '/your pattern match/{l++}END{print l}' yourfile`
f=`grep -c "your pattern match" yourfile`

awk '(l>2){print "too much"}/your pattern match/{l++}' yourfile
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question