Solved

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

Posted on 2014-12-10
2
125 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will giveā€¦
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

731 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