grep command

zgrep 'xyz'  abc.log.2018111212| grep '|[1-9][0-9][0-9][0-9][0-9]|0000' | wc -l

i am trying to figure out what above grep doing?

what is meaning of
|[1-9][0-9][0-9][0-9][0-9]|0000

wc -l means some kind of word count?
what is -l

any good links or resources or video tutorials to master greps and awk and sed end to end to debug server logs?

please advise
LVL 7
gudii9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

omarfaridCommented:
Each [ ] pair means single char any of digits from 0 to 9 or for rest 1 to 9 repeated 3 times
| means OR
0000 means string of 4 0 at least
-l means count words
Alfredo Luis Torres SerranoASP .Net DeveloperCommented:
It is a regular expression matching digits

refer to this link
omarfaridCommented:
| between commands means pass output to next command
Price Your IT Services for Profit

Managed service contracts are great - when they're making you money. Yes, you’re getting paid monthly, but is it actually profitable? Learn to calculate your hourly overhead burden so you can master your IT services pricing strategy.

nociSoftware EngineerCommented:
grep might need to be egrep or grep -e to actualy understand the  extended regex.
wc -l means count lines not characters or words.
(without options you get a count for characters, words and lines from a file).
gudii9Author Commented:
zgrep 'xyz'  abc.log.2018111212| grep '|[1-9][0-9][0-9][0-9][0-9]|0000' | wc -l

Open in new window

so we are searching on xyz on that log file called abc.log.2018111212


on top of results we are grepping for what numbers?

[1-9][0-9][0-9][0-9][0-9 ??

to find word count
gudii9Author Commented:
it is like greek and latin to me
gudii9Author Commented:
If you're using the regular expression to validate input, you'll probably want to check that the entire input consists of a valid number. To do this, replace the word boundaries with anchors to match the start and end of the string: ^([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$.

Here are a few more common ranges that you may want to match:

000..255: ^([01][0-9][0-9]|2[0-4][0-9]|25[0-5])$
0 or 000..255: ^([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$
0 or 000..127: ^(0?[0-9]?[0-9]|1[01][0-9]|12[0-7])$
0..999: ^([0-9]|[1-9][0-9]|[1-9][0-9][0-9])$
000..999: ^[0-9]{3}$
0 or 000..999: ^[0-9]{1,3}$
1..999: ^([1-9]|[1-9][0-9]|[1-9][0-9][0-9])$
001..999: ^(00[1-9]|0[1-9][0-9]|[1-9][0-9][0-9])$
1 or 001..999: ^(0{0,2}[1-9]|0?[1-9][0-9]|[1-9][0-9][0-9])$
0 or 00..59: ^[0-5]?[0-9]$
0 or 000..366: ^(0?[0-9]?[0-9]|[1-2][0-9][0-9]|3[0-5][0-9]|36[0-6])$

Open in new window

not clear on above either
nociSoftware EngineerCommented:
if using egrep:  you are searching for empty string or  4 digistring (exclude first number of 0)  or 0000 in the line.

 using grep : search the log file for xyz then search in those result for '|xyyy|0000'
xyyy  x is a digit from 1 to 9 inclusive, the y's are digits from  0 to 9 inclusive.

and then counting lines that matched the last grep.
nociSoftware EngineerCommented:
regular expresions are a method for searching data in strings...

^ start of string
$ end of string
. match anything
[] match a class of things
? match previous entryi 0 or 1 time
* match previous entry 0 or more times
+ match previous entry 1 or more times
{x}  = match previous {x,x} times
{x,y} = match previous expression minimal x and maximal y times.
anything else matches itself.

Classes:
[a-z] = a character range from lowercase a to lowercase z  including a and z.
[0-9] = [0123456789] = match one singe digit.
[;alnum;] == [0-9a-zA-Z]  = alphabetic or numeric item

for more info see:
https://perldoc.perl.org/perlre.html
https://www.tutorialspoint.com/python/python_reg_expressions.htm

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author Commented:
is any online tool where i can execute these commands and understand clearly what you guys mentioning
nociSoftware EngineerCommented:
Here are 2 examples for rexes testing.
https://regex101.com/
https://regexr.com/
arnoldCommented:
the first part is looking for a pattern of xyz in the compressed log.
Then each line is passed to the next group that is looking for a numerical pattern of |10000-99999|0000
Without seeing what the results of the first query, it is hard to see what your second part is looking for and whether the pattern is right.
| can be use as a logical OR.

wc is a counter of bytes, words, new lines (effectively lines, distinction deals with any wrapped lines visually) count as one long line...).

i.e. if you write a paragraph that wraps when you look at the output it seems like four or five lines, while in actuality it is a single long line. The wrapping and visual representation of the lines depends on the settings of the page margins.

Please when you post similar question, please provide a sample of the data being analyzed, and highlight the information you are trying to get as the end result.

in the current scheme you can get 0 as a response, i.e. no lines founds mathing your criteria.
The sequence you are using is an AND ie the first part has to match and the second patter has to match, then it will be counted.

As other pointed out, egrep, can process a comparison
https://www.thegeekstuff.com/2011/10/grep-or-and-not-operators

the [1-9][0-9]{4} is an equivalent pattern the [1-9][0-9][0-9][0-9][0-9]
[] means a single literal match whatever you place in there is interpreted literally since - has a special meaning as a range, if you need to match a dash, you have to escape (\) as a \-..

When I learned how to handle regular expression, the simplest thing I found was to go from left to right and run each section.
To see what is the output from zgrep.
Then I pass this output to grep
then I pass the resulting output to the counter (wc -l)
each stage you can see what you get and what is being evaluated.....
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.