Grepping only dates from a log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grepping only dates from a log file
# 22  
Old 05-29-2014
I told you to use nawk if you are using sunos/solaris in post #12, you must have forgotten Smilie, anyways glad to know that you finally got what you expected.
# 23  
Old 05-29-2014
Hey Akshay,
Tried using nawk as well
Code:
bash-3.00$ nawk --re-interval 'match($0,/([[:digit:]]{2}\/){2}[[:digit:]]{4}/,m){print $1, m[0]}' dump1.log
nawk: unknown option --re-interval ignored
nawk: syntax error at source line 1
context is
>>> match($0,/([[:digit:]]{2}\/){2}[[:digit:]]{4}/, <<<
nawk: bailing out at source line 1

Even for the last command i got error for awk, wut when i ran it as nawk it worked. for every command you gave i tried it using both awk & nawk.
How ever, it worked for me.. thank a lot for your time.... !!!

---------- Post updated at 07:03 AM ---------- Previous update was at 07:00 AM ----------

hope i am not harassing you with my silly doubts...

I have another basic doubt.

I want to run a script file as root, but inside that i need a command that needs to run as different user, is that possible.

can we use
Code:
sudo -t <user> <script file>
pbrun -u <user>  <script file>

thanks again..!!

Last edited by Scott; 05-29-2014 at 09:04 AM.. Reason: Code tags
# 24  
Old 05-29-2014
Please use below one, --re-interval option is avaiable in gawk

Code:
$ nawk -F';' 'match($0,/[0-9]+\/[0-9]+\/[0-9]+/){print $1,substr($0,RSTART,RLENGTH)}' file

Code:
su -c <script>

# 25  
Old 05-29-2014
ok, say script.sh has the below lines, and i need to run the script as root or user. please tell me if this will work
Code:
#!/bin/bash

sudo -t wam /usr/local/wam/stopwam -r     ------- this needs run as wam user
/usr/local/web/stopweb -a                             --- this needs to run as root
/sbin/init 6                                                   --- need to run as root.

this is my requirement, and i need to schedule this job, and i need to give user (either root or wam) while scheduling it.

Last edited by Scott; 05-29-2014 at 10:20 AM.. Reason: Code tags, please...
# 26  
Old 05-29-2014
As someone already tagged this thread as solved, and you seem to be heading off in a tangent, I'd ask you, please, to start a new thread. Thanks.

And, despite all your fancy ways of trying to delineate your code, you would still be quicker using the code tags button, or typing [code]...[/code]!

The button looks like this:
Image
This User Gave Thanks to Scott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to read a log file and run 2nd script if the dates match

# cat /tmp/checkdate.log SQL*Plus: Release 11.2.0.1.0 Production on Mon Sep 17 22:49:00 2012 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production FIRST_TIME NEXT_TIME... (1 Reply)
Discussion started by: SarwalR
1 Replies

2. UNIX for Dummies Questions & Answers

How to write the dates between 2 dates into a file

Hi All, I am trying to print the dates that falls between 2 date variables into a file. Here is the example. $BUS_DATE =20120616 $SUB_DATE=20120613 Output to file abc.txt should be : 20120613,20120614,120120615,20120616 Can you pls help me accomplish this in LINUX. Thanks... (5 Replies)
Discussion started by: dsfreddie
5 Replies

3. UNIX for Dummies Questions & Answers

grepping log files

I have a log file and I have two unique strings which represent the start and end of the text I want to obtain. How can I get all the text inbetween this start string and the end string? Thanks (2 Replies)
Discussion started by: chrisjones
2 Replies

4. Shell Programming and Scripting

How to processing the log file within certain dates based on the file name

Hi I am working on the script parsing specific message "TEST" from multiple file. The log file name looks like: N3.2009-11-26-03-05-02.console.log.tar.gz N4.2009-11-29-00-25-03.console.log.tar.gz N6.2009-12-01-10-05-02.console.log.tar.gz I am using the following command: zgrep -a --text... (1 Reply)
Discussion started by: shyork2001
1 Replies

5. Shell Programming and Scripting

Grepping log file

Dear All, I have a log file that is dislpayed as: <msg time='2009-10-14T05:46:42.580+00:00' org_id='oracle' comp_id='tnslsnr' type='UNKNOWN' level='16' host_id='mtdb_a' host_addr='UNKNOWN' version='1'> <txt>14-OCT-2009 05:46:42 *... (19 Replies)
Discussion started by: x-plicit78
19 Replies

6. Shell Programming and Scripting

find log file between two dates

Dear All, Please can you help me to crack this query? If the log files for the task above all had a naming convention of myoutput_YearMonthDay.log (i.e. myoutput_20060215) How would you find only those log files created between the 10th and the 20th of each month going back the last 365 days.... (1 Reply)
Discussion started by: justin_mca
1 Replies

7. Shell Programming and Scripting

Grepping the last 30 minutes of a log file...

I need to know if anyone can assist me on how to grab the last (we'll just say "x" minutes) of a log file. How do you tell the grep command without specifying an exact window of time? (So relative instead of absolute.) Thanks, Jon (2 Replies)
Discussion started by: jtelep
2 Replies

8. Shell Programming and Scripting

grep a log file to filter previous dates

Hi, I have problem of filtering a log file from my perl script. #cat /data/pinpe.csv_20070731 | nawk -v FS=, '{print $1','$18','$22','$26}' | grep -w 100 | grep -w 1 | nawk '{print $4}' Below is the output: 2009-06-16 2009-01-29 2009-06-02 2008-03-05 2007-08-05 2007-09-24... (5 Replies)
Discussion started by: pinpe
5 Replies

9. Shell Programming and Scripting

grep a log file between 2 dates

Hi Currently I can grep a log file with the following command: $results = `grep -A 2 '^$date.$time.*' $log`; and the following arguments: $date = 2007/04/25 $time = 16:07 Log example: 2007/04/25 16:07:12.145701 2007/05/25 14:07:12.145701 2007/05/25 17:07:12.145701 2007/06/25... (37 Replies)
Discussion started by: Epiphone
37 Replies

10. Shell Programming and Scripting

help searching log file with dates

Im tyring to create a script that will show me any lines in a file with todays date and yesterdays, the date format in the file is as follows ----- amqxfdcx.c : 728 -------------------------------------------------------- 07/12/05 09:53:20 AMQ6109: An internal WebSphere MQ error has... (3 Replies)
Discussion started by: csaunders
3 Replies
Login or Register to Ask a Question