Milliseconds to Date in Sun OS 5.10


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Milliseconds to Date in Sun OS 5.10
# 1  
Old 03-26-2018
Milliseconds to Date in Sun OS 5.10

I am using Sun OS 5.10
I am Using nawk to extract specific column from csv file.
The third column of csv is the time in Milliseconds and I need to convert it to Date then save it in another csv file.

I am use this command to extract the columns I need and save it in tttn.csv

Code:
nawk 'BEGIN {FS = ","}; NR>1 split($42,a,"|") {print $3 "," $46 "," $48 "," 
$47 "," null "," null "," a[2] "," $6 "," $49 "," $7 "," $8 ","}' ttt.csv  > 
tttn.csv

What I should write to convert the third column $3 from milliseconds to Date
Here is on sample from the third column 1519208012.638884910 and I need to convert it to be in this format '02/21/2018 17:04:95'

How can I handle this task?

Last edited by vgersh99; 03-26-2018 at 02:32 PM.. Reason: code tags, please
# 2  
Old 03-26-2018
Code:
print strftime("%D %T", $3)

Code:
dt="date +\"%D %T\" -d @" $3
dt | getline $3
close (dt)
print $3


Last edited by rdrtx1; 03-26-2018 at 06:20 PM..
# 3  
Old 03-26-2018
Quote:
Originally Posted by rdrtx1
Code:
print strftime("%D %T", $3)

strftime is a GNU extension - Solaris' nawk is not gawk.

---------- Post updated at 04:49 PM ---------- Previous update was at 04:15 PM ----------

Here's the old Solaris hack - epoch->readable - don't have the OS right now to validate - YMMV:
Code:
currentEpoch='1519208012'
echo "0t${currentEpoch}=Y" | /usr/bin/adb

# 4  
Old 03-26-2018
Quote:
Originally Posted by rdrtx1
Code:
print strftime("%D %T", $3)

Code:
dt="date +\"%D %T\" -d @" $3
dt | getline $3
close (dt)
print $3

---------------------
Where should i write this commands

---------- Post updated at 05:03 PM ---------- Previous update was at 05:02 PM ----------

Quote:
Originally Posted by vgersh99
strftime is a GNU extension - Solaris' nawk is not gawk.

---------- Post updated at 04:49 PM ---------- Previous update was at 04:15 PM ----------

Here's the old Solaris hack - epoch->readable - don't have the OS right now to validate - YMMV:
Code:
currentEpoch='1519208012'
echo "0t${currentEpoch}=Y" | /usr/bin/adb

-----------------
Where Should I write this command
# 5  
Old 03-26-2018
You can try /usr/bin/adb like vgersh99 suggests (I'm not sure what format your date will appear in however) like this:

Code:
awk 'BEGIN {FS = ","}; NR>1 split($42,a,"|") {
TM=$3
sub(/[.].*$/,x,TM)
CMD="echo \"0t\" TM | /usr/bin/adb"
CMD  | getline tm
close (CMD)
print tm "," $46 "," $48 "," $47 "," null "," null "," a[2] "," $6 "," $49 "," $7 "," $8 ","}' ttt.csv > tttn.csv

or use perl like this:

Code:
awk 'BEGIN {FS = ","}; NR>1 split($42,a,"|") {
TM=$3
sub(/[.].*$/,x,TM)
CMD="perl -we '\''use POSIX ; print strftime(\"%m/%d/%Y %T\", localtime(" TM "))'\''"
CMD  | getline tm
close (CMD)
print tm "," $46 "," $48 "," $47 "," null "," null "," a[2] "," $6 "," $49 "," $7 "," $8 ","}' ttt.csv > tttn.csv

# 6  
Old 03-27-2018
Quote:
Originally Posted by Chubler_XL
You can try /usr/bin/adb like vgersh99 suggests (I'm not sure what format your date will appear in however) like this:

Code:
awk 'BEGIN {FS = ","}; NR>1 split($42,a,"|") {
TM=$3
sub(/[.].*$/,x,TM)
CMD="echo \"0t\" TM | /usr/bin/adb"
CMD  | getline tm
close (CMD)
print tm "," $46 "," $48 "," $47 "," null "," null "," a[2] "," $6 "," $49 "," $7 "," $8 ","}' ttt.csv > tttn.csv

or use perl like this:

Code:
awk 'BEGIN {FS = ","}; NR>1 split($42,a,"|") {
TM=$3
sub(/[.].*$/,x,TM)
CMD="perl -we '\''use POSIX ; print strftime(\"%m/%d/%Y %T\", localtime(" TM "))'\''"
CMD  | getline tm
close (CMD)
print tm "," $46 "," $48 "," $47 "," null "," null "," a[2] "," $6 "," $49 "," $7 "," $8 ","}' ttt.csv > tttn.csv

thanks for your reply but the first solution give the following error :
adb: syntax error on line 1 of (stdin) near "tm"

the second solution works but with very low performance

Could you please help me to enhance the performance or fix the fist solution error
note that I am using nawk because awk and gawk gives me errors too.
# 7  
Old 03-27-2018
Oh so you have gawk on your system then.

Give this a go:

Code:
gawk 'BEGIN {FS = ","}; NR>1 split($42,a,"|") {
print strftime("%D %T", $3) "," $46 "," $48 "," $47 "," null "," null "," a[2] "," $6 "," $49 "," $7 "," $8 ","}' ttt.csv > tttn.csv

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Milliseconds Not Capture

while I load the value using sqlldr the millisecond values not stored in oracle table. Value: '26-OCT-17 08.59.50.916000000 AM' CTL field: SRC_SYS_CRT_TS Position(23:48) "decode(:SRC_SYS_CRT_TS,null,sysdate-1,to_timestamp(:SRC_SYS_CRT_TS,'yyyy-mm-dd.hh24.mi.ss.FF'))", ... (1 Reply)
Discussion started by: priya1987
1 Replies

2. UNIX for Dummies Questions & Answers

Date difference in Sun OS 5.10

Hi, I need to find the difference between 2 dates in SunOS 5.10 input will be in(yyyymmdd) date1: 20131011 date2:20131012 my output shold be diff between two dates i.e 0,1,2,3 date2 is always greater than date1. if it handles even leap year then it wil be more helpful. thank u... (2 Replies)
Discussion started by: mohanalakshmi
2 Replies

3. Shell Programming and Scripting

How do I do a short delay (milliseconds) in a shell script?

I need to put a small delay into a shell script. I'm looking for something smaller than "sleep" - a second is way too long. I want to sleep something like 10 milliseconds. I've tried "usleep" and "nanosleep", but the script doesn't recognize them. I'm using the bash shell but I'm willing to... (9 Replies)
Discussion started by: harmlesscat
9 Replies

4. Solaris

Process execution time in milliseconds

Hey everyone, I'm coming from Linux where the top command gave me lots of process info (particularly CPU time in milliseconds) and I'm trying to find similar info in Solaris. So far I've looked at prstat and ps but neither give cpu time in milliseconds, both seem to have 1 second... (2 Replies)
Discussion started by: maniac_ie
2 Replies

5. Solaris

Yesterday's date on Sun solaris

Can someone help me with the command to get yesterday's date on Sun solaris?? (1 Reply)
Discussion started by: sachinkl
1 Replies

6. Shell Programming and Scripting

Getting Time in MilliSeconds with Perl

I use something like this in perl to get the date and time: use Time::localtime; use Time::gmtime; $tm = gmtime; $time_str = sprintf "%04d-%02d-%02d %02d:%02d:%02d", $tm->year + 1900, $tm->mon + 1, $tm->mday, $tm->hour, $tm->min, $tm->sec; It gives me something like this: 2010-08-26... (1 Reply)
Discussion started by: lforum
1 Replies

7. Shell Programming and Scripting

Convert milliseconds to standard time

hello, I have the uptime of the server showing as upTime=2427742050 How do I convert it to standard time. Thanks Chiru (1 Reply)
Discussion started by: chiru_h
1 Replies

8. Shell Programming and Scripting

how to use sleep comand for milliseconds?

how to use sleep comand for milliseconds? (3 Replies)
Discussion started by: brkavi_in
3 Replies

9. Programming

C time in milliseconds function.

I need a c function which return the time in: hour min sec and mil sec I am writing on unix os. (3 Replies)
Discussion started by: kamil
3 Replies

10. UNIX for Dummies Questions & Answers

useing date or other time style utility to get milliseconds.

hello everyone. im sure someone has run into the problem of timestamping files and end up haveing 2 files with the same name thus over writeing one of them. In my application i am trying to get a timestamp w/ milliseconds but i am haveing no luck and finding an answer in the man pages. I know... (3 Replies)
Discussion started by: Optimus_P
3 Replies
Login or Register to Ask a Question