Solved

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

Posted on 2014-12-10
2
128 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

623 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