Computing.Net > Forums > Unix > find the number of line with awk.

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

find the number of line with awk.

Reply to Message Icon

Name: T
Date: January 31, 2003 at 02:38:47 Pacific
OS: unix
CPU/Ram: -
Comment:

Dear all,
How I can find the number of line(that my string exists) with awk or sed (not grep).

for example :(my file)

xxxxaaaxxxx
rrrrrrrrrrrrrrrrrr
xxxxbbbbbxxxx
zzzzzaaazzzzz
zzzzzbbbbbzzzz

I want to search "bbbbb" and number of line
that the result is 3 (just first word that 's discovered)

Thanks ,
T




Sponsored Link
Ads by Google

Response Number 1
Name: David
Date: January 31, 2003 at 03:12:54 Pacific
Reply:

awk /bbbbb/ test | wc -l

(where test is the name of the file)



0

Response Number 2
Name: Danny Larouche
Date: January 31, 2003 at 07:26:18 Pacific
Reply:

the previous post will tell how many occurences has been found.

This one will return the record number:

awk '/bbb/ {print NR }' file

If you only need the first occurence:

awk '/bbb/ {print NR }' file|tail -1


0

Response Number 3
Name: Danny Larouche
Date: January 31, 2003 at 07:31:51 Pacific
Reply:

Oooppss,

First occurence line number is:

awk '/bbb/ {print NR }' file|head -1



0

Response Number 4
Name: James Boothe
Date: January 31, 2003 at 09:07:08 Pacific
Reply:

This solution prevents awk from processing the remainder of the file, and also avoids the second process:

awk '/bbb/ {print NR;exit}' myfile


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: find the number of line with awk.

Find the day of week using AWK www.computing.net/answers/unix/find-the-day-of-week-using-awk/5243.html

padding a number with leading zeros www.computing.net/answers/unix/padding-a-number-with-leading-zeros/5218.html

how to find the number of defunc process www.computing.net/answers/unix/how-to-find-the-number-of-defunc-process/2308.html