Solved

AWK: number of lines returned ?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Basic Regex for use in webservice 1 56
edit mobile phone number in office 365 15 51
PowerShell Regular Expression 2 38
batch file problem 5 18
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…

937 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

6 Experts available now in Live!

Get 1:1 Help Now