Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

685 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