Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can this be shortened? 1

Status
Not open for further replies.

Kipnep70

Technical User
Nov 18, 2003
81
US
I've written a one-liner that will search for pattern in a file and then print the total lines that a match was found on.

Code:
 awk '/HCART/ && !/NONE/ { $0=a++ }; END{ print a }'

Basically I was just trying to avoid 'wc -l' for fun. Is there a better way to do this?

Thanks
 
A shorter version:
Code:
awk '/HCART/&&!/NONE/{++a}END{print a}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

How about:
Code:
grep 'HCART' MyFile.txt|grep -vc 'NONE'
[noevil]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top