• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 68
  • Last Modified:

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
0
gudii9
Asked:
gudii9
  • 3
  • 2
2 Solutions
 
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
 
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
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
 
Murugesan NagarajanSubject-matter expert at C++ C delivery, implementation, at UNIX oriented operating systems (Windows: CYGWIN_NT MINGW32_NT MINGW64_NT)Commented:
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
 
Murugesan NagarajanSubject-matter expert at C++ C delivery, implementation, at UNIX oriented operating systems (Windows: CYGWIN_NT MINGW32_NT MINGW64_NT)Commented:
1. Provided best solution and answer to next queries
2. Tested given solutions
3. Inactive for 14 days
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now