Grep -i

Hi,

Cat alert_db.log |grep -i "Dec 04" > test.log

does not show complete line from alert log it shows only Dec 04 2012-13 so on .

I need full content to be written in test log whatever is there in alert_db.log written on Dec 04 2016 between 13:00:00 to 17:00:00 .

What command I should use?

Thanks in advance!!

Manish

You haven't bothered to tell us which version of the Solaris operating system you're using nor the shell you're using nor the path to the grep utility you're using on your Solaris system, so we can only make a wild guess that you're using a version of grep that makes use of a horrible environment variable like the one the GNU grep uses ( GREP_OPTIONS ) that defines options to be applied to every grep command you run and that you have defined this environment variable to contain the -o option (and maybe others as well).

So... look at the man page for the version of the grep utility you are using and search it for environment variables that affect the execution of grep commands; search the environment you're using when you invoke grep and it is misbehaving as described in your message; unset that variable; and try running your command again. Or try using /usr/bin/grep or /usr/xpg4/bin/grep instead of the version of grep you are using.

On most systems there is a cat command, but no Cat command; so the command line shown in your post is still not likely to work (and there is absolutely no reason to use cat for this command line unless you are trying to place more load on your system and slow down getting results). The command:

/usr/xpg4/bin/grep -i "Dec 04" alert_db.log > test.log

would be much preferable to the one you showed us in your post, but there is nothing in your command line that makes any attempt to restrict output to the time range you specified. And, since you haven't shown us the format of the data on the lines you're trying to print, we can again only make wild guesses at what might work for you. You could try something like:

/usr/xpg4/bin/grep -i 'Dec 04.*1[3-6]:[0-5][0-9]:[0-5][0-9]' alert_db.log > test.log

which will find and print lines that contain the string Dec 04 (in a case insensitive match) followed by anything following by a timestamp in the inclusive range 13:00:00 through 16:59:59 . But, depending on the format of your data and data that might follow timestamps in your data, this could easily display lines in addition to those that meet your criteria (i.e. false positives).

Your requirements are not clear as to whether or not the timestamp 17:00:00 should be selected for printing, whether the timestamp comes before or after the date, what range of years you want to select for printing, etc. Hopefully, the above information will give you enough to fix your RE to match whatever date and timestamps you really want to select.
___________________
Update:
The RE error noted in post #3 has been fixed.

1 Like

Don Cragun's carefully analysed and phrased post has a small hitch: the regex has one :00-59 range too many - drop one of the :[0-5][0-9] s.

1 Like

Thank you for catching my typo. That bug has now been fixed in post #2.