grep request differences

hi,

what are differences between below 3 grep requests


zgrep 'RPT|O|BundleShowing' nine.log.20171029.gz | grep 'Oct-29 23:' | wc -l


zgrep 'RPT|O|BundleShow' nine.log.20171029.gz | grep 'Oct-29 23:' | wc -l



zgrep 'RPT|O|BundleShowing' nine.log.20171029.gz | grep 'Oct-29 23:24' | wc -l


if i have to search from yesterday 11 pm till today morning say 6am how to refine my query.

please advise
LVL 7
gudii9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

ozoCommented:
The first and third may not match BundleShowstoppers or BundleShowcasing
The third may not match Oct-29 23:25 or Oct-29 23:23

grep may not be the best tool for matching a range of times
How tolerant are you of matching more than requested?  Do you mind getting all of yesterday, or all of today?
How about missing yesterday from 11pm to 11:59:59?

Assuming yesterday is Oct-29
egrep 'Oct-(29 23|30 0[0-5])'
could match from yesterday 11 pm till today 6am
0

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:
any good links or resources on this kind of sample queries?
0
gudii9Author Commented:
grep may not be the best tool for matching a range of times
what is the best tool
How tolerant are you of matching more than requested?  Do you mind getting all of yesterday, or all of today?
How about missing yesterday from 11pm to 11:59:59?
my requirement keep changing. tomorrow i may want to search on whole last week data or whole last month date.

any perfect examples to tweak those example queries?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

gudii9Author Commented:
The first and third may not match BundleShowstoppers or BundleShowcasing
does second match?
is it like wild card search if i do as below

zgrep 'RPT|O|BundleShow' nine.log.20171029.gz | grep 'Oct-29 23:' | wc -l


is above same as below (lets say 4th one)

zgrep 'RPT|O|BundleShow*' nine.log.20171029.gz | grep 'Oct-29 23:' | wc -l
0
murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NTCommented:
Hi gudii,

Learn the following:
1. Regular expressions => Example => https://ryanstutorials.net/linuxtutorial/grep.php => bing or google search => regular expression shell script
I have learned regular expression using textpad, HP-UX commands and http://www.google.com/ncr during 2003.
Now http://www.google.com/ncr => https://www.google.com/ncr
2. man zgrep or egrep or grep
3. Your comment was:
            zgrep 'RPT|O|BundleShow' nine.log.20171029.gz | grep 'Oct-29 23:' | wc -l
            is above same as below (lets say 4th one)
            zgrep 'RPT|O|BundleShow*' nine.log.20171029.gz | grep 'Oct-29 23:' | wc -l
Consider following input file which is having BundleSho in last line:
/bin/cat nine.log.20171029
RPT|O|BundleShowing Oct-29 23:
RPT|O|BundleShow Oct-29 23:
RPT|O|BundleShowing Oct-29 23:24
RPT|O|BundleSho Oct-29 23:

Open in new window

gzipping the file:
/usr/bin/gzip nine.log.20171029

Open in new window

Following command is not displaying the last line "BundleSho Oct-29 23:"
/bin/zgrep 'RPT|O|BundleShow' nine.log.20171029.gz | /bin/grep 'Oct-29 23:'
RPT|O|BundleShowing Oct-29 23:
RPT|O|BundleShow Oct-29 23:
RPT|O|BundleShowing Oct-29 23:24

Open in new window

However following command is displaying the last line:
/bin/zgrep 'RPT|O|BundleShow*' nine.log.20171029.gz | /bin/grep 'Oct-29 23:'
RPT|O|BundleShowing Oct-29 23:
RPT|O|BundleShow Oct-29 23:
RPT|O|BundleShowing Oct-29 23:24
RPT|O|BundleSho Oct-29 23:

Open in new window

Meaning of * in regular expression is zero or more occurrences of previous character.
BundleShow*
Hence we are searching for the word BundleSho followed by zero or more occurrences of the character w.
Hence it is displaying the last line.
4. Always use full path when executing any commands:
/bin/grep
/bin/egrep
/bin/zgrep
/usr/bin/wc
/usr/bin/gzip
/usr/bin/gunzip
/bin/awk or /bin/gawk or /usr/bin/awk or /usr/bin/gawk
5. Reason for using full path:
unset -f ls
unalias ls >/dev/null 2>&1
ls ()
{
      echo "Use following command when using ls: "
      echo "/bin/ls $@"
      Ret=$?
      return $Ret
}
ls -latr
Use following command when using ls:
/bin/ls -latr

Open in new window

0
murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NTCommented:
1. Provided best solution and answer to next queries
2. Tested given solutions
3. Inactive for 14 days
0
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.