#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Convert Date in different format


    Hi,

    My input is Jan 03 2011....I need to get this [Jan 03 2011] as input and display the output in the format 01/03/2011 05:57

    Please help me with the option to convert the date format as expected.

    Regards,
    thangaga
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,477
    Rep Power
    1752
    You 'just' need to convert the three character month abbreviation to a number and juggle the order of the fields and display. What/how you deal with the time I have no clue as that does not seem to be part of your input.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0
    My find command is giving the output in the format [Jan 4 05:11]

    I want to display that 1/4/2011 05:11

    I have tried below options with ls command but not working in Solaris:
    ls -l --time-style="+%m/%d/%Y %H:%M"
    ls -l --full-time


    Good comment to denote confused
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,477
    Rep Power
    1752
    Ok, using bash (by assumption from the command format, within Solaris) ... and you want the output date/time-stamp to be in a specific format, correct?

    A quick man ls under a bash shell (extract only!) shows:
    --time-style=STYLE
    with -l, show times using style STYLE: full-iso, long-iso, iso, locale, +FORMAT. FORMAT is interpreted
    like ‘date’; if FORMAT is FORMAT1<newline>FORMAT2, FORMAT1 applies to non-recent files and FORMAT2 to
    recent files; if STYLE is prefixed with ‘posix-’, STYLE takes effect only outside the POSIX locale
    It looks like the +FORMAT is going to be what you want. And that IS what you are using ... are you sure you are in a bash shell? What happens when you try - apart from the generic 'not working'?
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0
    I am getting the output in the format Jan 5 2011, but I want to display in the format 1/5/2011 12:00

    Command: find /appbin/gentran/gis43/logs -name "noapp.log.*" -mtime -7 -ls -E | awk '{print $8,$9,$10}'

    Output:
    find: bad option -E
    find: [-H | -L] path-list predicate-list

    E option is not working in find command. Later, i tried with ls command

    Command: find /appbin/gentran/gis43/logs -name "noapp.log.*" -mtime -7 | ls -E

    Output:
    It is not giving the list of files from the folder /appbin/gentran/gis43/logs. But, it's just giving the list of files which are in local folder.

    Command: ls -l --time-style="+%m/%d/%Y %H:%M" check

    Output:
    ls: illegal option -- time-style=+%m/%d/%Y %H:%M
    usage: ls -1RaAdCxmnlhogrtuvVcpFbqisfHLeE@ [files]

    Command: ls -l --full-time check

    Output:
    ls: illegal option -- full-time
    usage: ls -1RaAdCxmnlhogrtuvVcpFbqisfHLeE@ [files]
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,477
    Rep Power
    1752
    Ok, we have a few issues!
    First -
    Code:
    Command: find /appbin/gentran/gis43/logs -name "noapp.log.*" -mtime -7 -ls -E | awk '{print $8,$9,$10}'
    
    Output:
    find: bad option -E
    find: [-H | -L] path-list predicate-list
    That is telling you that -E is not a valid option for the find command.
    Try:
    Code:
    Command: find /appbin/gentran/gis43/logs -name "noapp.log.*" -mtime -7 -exec -ls -E {} \; | awk '{print $8,$9,$10}'
    Pretty much the same thing for the next one - you need to tell the find command to run the ls for you, by using -exec and specifying {} \; as parameters to the ls so that find will replace that with each entry it finds:

    Code:
    find /appbin/gentran/gis43/logs -name "noapp.log.*" -mtime -7 -exec ls -E {} \;
    The space between the {} and \; is needed!

    Your next two deal with the ls command, and you are using options that are only valid within the bash shell, try:

    Code:
    bash
    ls -l --time-style="+%m/%d/%Y %H:%M" check
    exit
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Smile


    Thank you so much!

    It is working now...

    Really the explanations are very good..

    In find option, i had seen the option -exec and {} \ .....but i ma not sure why it is?

    Now i understood why we are using?

    Once again thanks!
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,477
    Rep Power
    1752
    A pleasure - I figured the additional explanations might come in useful. Glad it all workd out.

    By the way ... just as an aside, in case you get caught by it like I did. Using standard Solaris there can be two different versions of ps and grep (and a few others) - one i sthe 'bog-standard' variery in /usr/bin the other is a Posix-compliant version in something like /usr/xpg4/bin. A LOT of people like using the Posix one, work out a nice little bit of script code using grep, put it in a script with a #!/usr/bin/sh shebang line and then complain it's broken. Because, suddenly, the command does not work, it is being run in an environment (often via cron) where the /usr/xpg4/bin directory is not in the PATH. I spent a goodly while scratching my head on that one when a developer had the problem!
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo