?
Solved

How do I show date in MM/DD/YYYY format in bash on a Solaris 10 system?

Posted on 2009-12-29
4
Medium Priority
?
427 Views
Last Modified: 2013-12-27
I tries to gray some info from a file:

#!/bin/bash
today_date=`date +'%a %b %e'`
rm /scripts/TSU_output.txt 2>/dev/null
grep -i "$today_date" /home/ftran/xferlog >> /scripts/TSU_output.txt
mailx -s "Xferlog from Oiler ${today_date}" abc@abc.com < /scripts/TS
U_output.txt

the output of the script is:
Tue Dec 29 00:33:49 EST 2009 * *  Processing SUCCESSFUL - cr867r01.09363
Tue Dec 29 00:33:50 EST 2009 * *  Processing SUCCESSFUL - cr867r02.09363
Tue Dec 29 00:33:51 EST 2009 * *  Processing SUCCESSFUL - cr867r03.09363
Tue Dec 29 00:33:53 EST 2009 * *  Processing SUCCESSFUL - cr867r04.09363
Tue Dec 29 00:33:54 EST 2009 * *  Processing SUCCESSFUL - cr867r05.09363
Tue Dec 29 00:33:55 EST 2009 * *  Processing SUCCESSFUL - cr867r06.09363
Tue Dec 29 00:33:56 EST 2009 * *  Processing SUCCESSFUL - cr867r07.09363
Tue Dec 29 00:39:24 EST 2009 * *  Processing SUCCESSFUL - ir115r01.09363
Tue Dec 29 00:50:35 EST 2009 * *  Processing SUCCESSFUL - bd250r01.09363
Tue Dec 29 04:58:21 EST 2009 * *  Processing SUCCESSFUL - ir115r01.09363

is there a way I can make it to come up as:
12/29/2009 04:58:21 EST 2009 * * ir115r01.09363 Processing SUCCESSFUL

without changing the original file xferlog?
0
Comment
Question by:USTTN-LAN
  • 2
  • 2
4 Comments
 
LVL 58

Accepted Solution

by:
amit_g earned 200 total points
ID: 26139026
Change

grep -i "$today_date" /home/ftran/xferlog >> /scripts/TSU_output.txt

to

grep -i "$today_date" /home/ftran/xferlog | awk '{print "date +\"%m/%d/%Y %H:%M:%S" substr($0, 15) "\" -d \"" substr($0, 1, 28) "\""}' | sh >> /scripts/TSU_output.txt
0
 

Author Closing Comment

by:USTTN-LAN
ID: 31670774
Thank you very much
0
 

Author Comment

by:USTTN-LAN
ID: 26140067
The output becomes:

12/29/2009 13:40:1133:49 EST 2009 * *  Processing SUCCESSFUL - cr867r01.09363
12/29/2009 13:40:1133:50 EST 2009 * *  Processing SUCCESSFUL - cr867r02.09363
12/29/2009 13:40:1133:51 EST 2009 * *  Processing SUCCESSFUL - cr867r03.09363
12/29/2009 13:40:1133:53 EST 2009 * *  Processing SUCCESSFUL - cr867r04.09363
12/29/2009 13:40:1133:54 EST 2009 * *  Processing SUCCESSFUL - cr867r05.09363
12/29/2009 13:40:1133:55 EST 2009 * *  Processing SUCCESSFUL - cr867r06.09363
12/29/2009 13:40:1133:56 EST 2009 * *  Processing SUCCESSFUL - cr867r07.09363
12/29/2009 13:40:1139:24 EST 2009 * *  Processing SUCCESSFUL - ir115r01.09363
12/29/2009 13:40:1150:35 EST 2009 * *  Processing SUCCESSFUL - bd250r01.09363
12/29/2009 13:40:1158:21 EST 2009 * *  Processing SUCCESSFUL - ir115r01.09363

What happens to the time stamp?
0
 
LVL 58

Expert Comment

by:amit_g
ID: 26140109
Have you worked it out?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question