Solved

what is the syntax to get the count of 2 or more strings..

Posted on 2014-12-10
2
117 Views
Last Modified: 2014-12-13
Hi,
I want to grep a file for 2 or more strings and get a count back.

for one string I have this..
RETVAL=`egrep -c '(PLS)-' ${my_file}`

what is the syntax to get the count of 2 or more strings..

if my file has any of these strings return the count
file name = "my_file"
strings="PLS" and "ORA" and "ERR"

Thx, Bill
0
Comment
Question by:bcarlis
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 40492261
Do you mean the cumulative count?

RETVAL=$(egrep -c 'PLS|ORA|ERR' $my_file)
echo $RETVAL

If you have to check for the presence of the parentheses and the minus sign (as in your example):

RETVAL=$(egrep -c '\(ORA\)-|\(ERR\)-|\(PLS\)-' $my_file)
echo $RETVAL

To count multiple matches per line (GNU grep only):

RETVAL=$(egrep -o '\(ORA\)-|\(ERR\)-|\(PLS\)-' $my_file |wc -l)
echo $RETVAL
0
 
LVL 2

Author Closing Comment

by:bcarlis
ID: 40498483
Thank you!
RETVAL=$(egrep -c 'PLS|ORA|ERR' $my_file)
works great!
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

747 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

10 Experts available now in Live!

Get 1:1 Help Now