Results 1 to 8 of 8

Thread: Date Conversion

  1. #1
    Join Date
    Oct 2005
    Posts
    92

    Unanswered: Date Conversion

    Hi All,

    i have a directory such as;

    find /home/pavi/ctl/INFOSCAN.KKK.*.*.ctl* -exec ls -ltr {} \; | awk -F" " {'print $6 " " $7'}

    the output is : Jul 25

    can anyone please suggest me how do I convert the above into YYYYMMDD FORMAT.

    Thanks
    pavi

  2. #2
    Join Date
    Dec 2003
    Location
    Oklahoma, USA
    Posts
    354
    First, the part that looks like this:

    Code:
    -exec ls -ltr {}
    should be something like:

    Code:
    -exec ls --full-time {}
    "ls --full-time" will output the file listing as:

    Code:
    -rw-rw---- 1 oracle dba  1024 2006-07-26 05:00:00.0000000 -500 filename.sql
    From there, you just need to adjust your awk script.

    Secondly, you have posted this in the wrong forum...
    JoeB
    save disk space, use smaller fonts

  3. #3
    Join Date
    Oct 2005
    Posts
    92

    Date conversion

    Thanks a lot.
    what is the right forum for these kind of Q's.

    Thanks
    pavi

  4. #4
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    Actually, I would go to WWW.UNIX.COM for any unix scripting questions. It is a large UNIX forum and you can register for free.
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  5. #5
    Join Date
    May 2004
    Location
    Dominican Republic
    Posts
    721
    This is a rather non-generic task. For example, that doesn't work on any of our servers (HP Tru64 and Solaris mostly).

  6. #6
    Join Date
    Jul 2003
    Posts
    2,296
    take that output, pass it into sqlplus and convert it on the fly:

    PHP Code:
    system@db1select to_date('Jul 25','Mon dd'from dual;

    TO_DATE('JUL25'
    ---------------
    072506 00:00:00

    system
    @db1edit
    Wrote file afiedt
    .buf

      1
    select to_char(to_date('Jul 25','Mon dd'), 'YYYYMMDD'from dual
    system
    @db1> /

    TO_CHAR(
    --------
    20060725 
    - The_Duck
    you can lead someone to something but they will never learn anything ...

  7. #7
    Join Date
    May 2004
    Location
    Dominican Republic
    Posts
    721
    But how do you know which year Jul 25 is? (granted, ls -l will have the year if its 6 month older.. but I am only having Month day as input).

    However, I have managed to do this with perl.
    Code:
    #
    # ls -l ls.pl
    -rwxr-xr-x   1 root     other        138 Jul 27 14:59 ls.pl
    #
    # more ls.pl
    #!/usr/bin/perl -w #-d
    $mtime=(stat($ARGV[0]))[9]; @ltime=localtime $mtime;
    printf "%.4d%.2d%.2d\n",$ltime[5]+1900,$ltime[4]+1,$ltime[3];
    #
    # find / -name 'ls.pl' -type f -exec basename {} \; | xargs -i ./ls.pl {}
    20060727
    #

  8. #8
    Join Date
    Jul 2003
    Posts
    2,296
    why would it be 2005?
    Are you loading a new file everyday or are these year-old files?
    - The_Duck
    you can lead someone to something but they will never learn anything ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •