Sponsored Content
Top Forums Shell Programming and Scripting Converting date string to different formats Post 302419741 by kshji on Saturday 8th of May 2010 10:10:15 AM
Old 05-08-2010
Something like this. Format date yyyymmdd, then you can use numeric comparing.
You need fix the awk substr lines. Look values from real loglines.
Code:
#!/bin/ksh or bash or ...
datestr()
{
input=$1
oifs="$IFS"
IFS="."
values=($input)
IFS="$oifs"
d=${values[0]}
m=${values[1]}
y=${values[2]}
datestr="$y$m$d"
}

date1=$(datestr 12.10.2009)
date2=$(datestr 12.10.2010)

awk -v d1=$date1 -v d2=$date2 '
/access[0-9][0-9]/ {
    datestr=substr($0:7:6}
    datelong=sprintf("20%s",datestr)
    if (datelong < d1  || datelong > d2) { next }
    print $0
    next
    }
/HTTP_[0-9][0-9]/ {
    datelong=substr($0:6:6}
    if (datelong < d1  || datelong > d2) { next }
    print $0
    next
    }
/http_log.*[0-9][0-9]/ {
    y=substr($0:14:4}
    m=substr($0:19:2}
    d=substr($0:22:2}
    datelong=sprintf("%s%s%s",y,m,d)
    if (datelong < d1  || datelong > d2) { next }
    print $0
    next
    }
' logfile

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

date formats

Hi, I want to generate file name in the following date format, "YYYYMMDDHHHHMISS" plz. help me how to do that? (6 Replies)
Discussion started by: harshad.katruwa
6 Replies

2. HP-UX

a simple way of converting a date in seconds to normal date

Hi all! I'm working on a HPUX system, and I was wondering if there is a simple way to convert a date from seconds (since 1970) to a normal date. Thanks (2 Replies)
Discussion started by: travian
2 Replies

3. Solaris

different date formats in same server

when I ssh and run date command, it shows date in 24 hour date format. But when I telnet the same server, it shows date in 12 hour format, ie. in AM/PM (1 Reply)
Discussion started by: na75369
1 Replies

4. UNIX for Dummies Questions & Answers

Help with Date Formats

Hi, Following are the results of various date formats: 1. date +%h" "%d Result: Jun 02 2. date Result: Tue Jun 2 09:59:15 CDT 2009 If i use the date format as date +%h%d then i am getting the date as 02. I want the day to be displayed as "2" instead of "02". so my result should... (1 Reply)
Discussion started by: sandeep_1105
1 Replies

5. Shell Programming and Scripting

Converting string to date in perl

Hi, I need convert a date string to date. For eaxmple $last_date=6/2/2009 and I want to change the format of the above mentioned date to "Jun 2 2009 12:00AM". Do we have any functionality or staright method to convert to the desired format? (4 Replies)
Discussion started by: siba.s.nayak
4 Replies

6. Shell Programming and Scripting

Extracting data from a log file with date formats

Hello, I have a log file for the year, which contains lines starting with the data in the format of YYYY-MM-DD. I need to get all the lines that contain the DD being 04, how would I do this? I tried using grep "*-*04" but it didn't work. Any quick one liners I should know about? Thank you. (2 Replies)
Discussion started by: cpickering
2 Replies

7. Shell Programming and Scripting

Converting a date to friday date and finding Min/Max date

Dear all, I have 2 questions. I have a file with many rows which has date of the format YYYYMMDD. 1. I need to change the date to that weeks friday date(Ex: 20120716(monday) to 20120720). Satuday/Sunday has to be changed to next week friday date too. 2. After converting the date to... (10 Replies)
Discussion started by: 2001.arun
10 Replies

8. UNIX for Dummies Questions & Answers

Converting string date time to unix time in AWK

I'd like to convert a date string in the form of sun aug 19 09:03:10 EDT 2012, to unixtime timestamp using awk. I tried This is how each line of the file looks like, different date and time in this format Sun Aug 19 08:33:45 EDT 2012, user1(108.6.217.236) all: test on the 17th ... (2 Replies)
Discussion started by: bkkid
2 Replies

9. Shell Programming and Scripting

Perl:: mass replacement of converting C code formats to tgmath.h

hello, i have a lot of C old code I'm updating to C11 with tgmath.h for generic math. the old code has very specific types, real and complex, like cabsl, csinhl, etc usually for simple bulk replacements i would do something simple like this perl -pi -e 's/cosl/cos/g' *.c the reference... (0 Replies)
Discussion started by: f77hack
0 Replies

10. Shell Programming and Scripting

Converting String Date into UNIX Date

Hi, I have a string date to my unix script(sun solaris). I wanted to convert it into unix date so that I can use it in a conditional statement. Please see below: MyTest.sh -s 2018-05-09 suppdt=$1 # string date passed via arguement as 2018-04-09 curryr=`date '+%Y'` nextyr=`expr... (2 Replies)
Discussion started by: Saanvi1
2 Replies
mailq(1)							   User Commands							  mailq(1)

NAME
mailq - print the mail queue SYNOPSIS
/usr/bin/mailq [-Ac] [-q subarg] [-v] DESCRIPTION
The mailq utility displays a summary of the mail messages queued for future delivery. The first line displayed for each mail message shows the internal identifier used on this host for the message, the size of the message in bytes, the date and time the message was accepted into the queue, and the envelope sender of the message. The second line of the display shows the error message that caused this message to be retained in the queue. This line will not be displayed if the message is being pro- cessed for the first time. The mailq utility used to be identical to sendmail -bp. Now it checks for the authorization attribute, solaris.mail.mailq. If the check for the invoking user succeeds, sendmail -bp is executed with the remaining argument vector. Otherwise, an error message is printed. This authorization attribute is by default enabled for all users. It can be disabled by modifying the Basic Solaris User entry in prof_attr(4). OPTIONS
The following options are supported: -Ac Like sendmail(1M), this flag tells mailq to use submit.cf rather than sendmail.cf even if the operation mode does not indicate an initial mail submission. This will result in the client queue /var/spool/clientmqueue being displayed rather than the default server queue /var/spool/mqueue. -qp[time] Similar to -qtime, except that instead of periodically forking a child to process the queue, sendmail forks a single per- sistent child for each queue that alternates between processing the queue and sleeping. The sleep time is given as the argument. The sleep time default is 1 second. The process will always sleep at least 5 seconds if the queue was empty in the previous queue run. -qf Processes saved messages in the queue once and does not fork(), but runs in the foreground. -qG name Processes jobs in the queue group called name only. -q[!]I substr Limits processed jobs to those containing substr as a substring of the queue id, or not when ! is specified. -q[!]R substr Limits processed jobs to those containing substr as a substring of one of the recipients, or not when ! is specified. -q[!]S substr Limits processed jobs to those containing substr as a substring of the sender, or not when ! is specified. -v Prints verbose information. This adds the priority of the message and a single character indicator (+ or blank) indicating whether a warning message has been sent on the first line of the message. Additionally, extra lines may be intermixed with the recipients that indicate the "controlling user" information. This shows who will own any programs that are executed on behalf of this message and the name of the alias this command is expanded from, if any. EXIT STATUS
0 Successful completion. >0 An error occurred. FILES
/etc/security/prof_attr local source for execution profile attributes /var/spool/mqueue default server queue /var/spool/clientmqueue client queue ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWsndmu | +-----------------------------+-----------------------------+ SEE ALSO
sendmail(1M), prof_attr(4), attributes(5) SunOS 5.10 10 Jul 2002 mailq(1)
All times are GMT -4. The time now is 10:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy