Unix/Linux Go Back    


Solaris The Solaris Operating System, usually known simply as Solaris, is a Unix-based operating system introduced by Sun Microsystems. The Solaris OS is now owned by Oracle.

Grep -i

Solaris


Tags
grep -e

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-10-2016
manish_1678 manish_1678 is offline
Registered User
 
Join Date: Aug 2010
Last Activity: 11 December 2016, 12:26 AM EST
Posts: 19
Thanks: 2
Thanked 0 Times in 0 Posts
Grep -i

Hi,


Code:
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
Moderator's Comments:
Grep -i You have been reminded several times before to use CODE tags when displaying sample input, sample output, and code segments. You have been placed in read-only mode for a while and reminded to review the rules you agreed to when you joined this forum before when you violated several rules in one post. Continued rule violations may lead to you being permanently barred from this site.

Last edited by Don Cragun; 12-10-2016 at 02:56 AM.. Reason: Add CODE and ICODE tags, again.
Sponsored Links
    #2  
Old Unix and Linux 12-10-2016
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is online now Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 24 January 2017, 12:03 PM EST
Location: San Jose, CA, USA
Posts: 9,884
Thanks: 477
Thanked 3,391 Times in 2,896 Posts
Quote:
Originally Posted by manish_1678 View Post
Hi,


Code:
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
Moderator's Comments:
Grep -i You have been reminded several times before to use CODE tags when displaying sample input, sample output, and code segments. You have been placed in read-only mode for a while and reminded to review the rules you agreed to when you joined this forum before when you violated several rules in one post. Continued rule violations may lead to you being permanently barred from this site.
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:

Code:
/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:

Code:
/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.

Last edited by Don Cragun; 12-10-2016 at 12:58 PM.. Reason: Fix typo noted in post #3: s/:[0-5][0-9]:[0-5][0-9]/:[0-5][0-9]/
The Following User Says Thank You to Don Cragun For This Useful Post:
jim mcnamara (12-10-2016)
Sponsored Links
    #3  
Old Unix and Linux 12-10-2016
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 24 January 2017, 12:12 PM EST
Location: Aachen, Germany
Posts: 10,170
Thanks: 233
Thanked 3,077 Times in 2,853 Posts
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.
The Following User Says Thank You to RudiC For This Useful Post:
Don Cragun (12-10-2016)
    #4  
Old Unix and Linux 12-10-2016
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is online now Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 24 January 2017, 12:03 PM EST
Location: San Jose, CA, USA
Posts: 9,884
Thanks: 477
Thanked 3,391 Times in 2,896 Posts
Quote:
Originally Posted by RudiC View Post
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.
Thank you for catching my typo. That bug has now been fixed in post #2.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` wtolentino Shell Programming and Scripting 6 07-30-2014 06:04 PM
Piping grep into awk, read the next line using grep Paul Moghadam UNIX for Dummies Questions & Answers 2 12-10-2013 12:58 AM
Bash - CLI - grep - Passing result to grep through pipe jcdole UNIX for Dummies Questions & Answers 1 04-29-2012 07:20 PM
| help | unix | grep (GNU grep) 2.5.1 | advanced regex syntax MykC UNIX for Dummies Questions & Answers 4 10-15-2009 11:52 AM
MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else hariza Shell Programming and Scripting 4 09-18-2008 03:56 AM



All times are GMT -4. The time now is 01:18 PM.