Solved

AWK: number of lines returned ?

Posted on 2007-11-20
5
1,030 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
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now