Casting the data command !


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Casting the data command !
# 1  
Old 08-01-2014
Casting the data command !

Hey guys.

1st problem:
I have to create a script for every hour run a script against a DB and then produce results to log file and eventually email.

I have to manipulate the date command from something like this
Code:
date '+%F %H:%M.%s'

which produces the below the below result
Code:
2014-08-01 15:20.1406920806

TO:
to be like this
Code:
>> 2014-08-01 15:20.140692

I need less digits to show of for %s command> I must maintain same format though for the script as it matches DB format.
Thanks!

Moderator's Comments:
Mod Comment Code tags for code, PLEASE!

Last edited by Corona688; 08-01-2014 at 06:13 PM..
# 2  
Old 08-01-2014
Hammer & Screwdriver

You can get exactly what you asked for with

Code:
$ VAR=$(date +"%F %H:%M.%s")
$ echo ">> ${VAR:0:23}"
>> 2014-08-01 14:23.140692

...but I have my doubts that's what you actually want.

What, exactly, is your database's format? %s is not seconds, %s is epoch time -- the total number of seconds since Jan 1, 1970, the dawn of UNIX. Chopping 4 digits off that doesn't make sense, it wasn't always 10 digits long.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 08-03-2014
thanks for the heads up I though s% was a deatiled seconds but I was wrong... lol

Code:
date +"%F %H:%M.0000

it generates the right number of zeros for me to compare to system code epoch time ! Smilie `plus less work I dont need to round number the seconds column any more lol which was unnecessary

Thanks again Corona Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Very strange output with casting

Hi All, I am having a strange issue. Below is the code snippet. If I print fraction * (double)::pow((double)10,scalingFactor) which is a double I am getting 154 when I type cast that to int as (int)( ((fraction) * ((double)::pow((double)10,scalingFactor)))) it is becoming 153. Not sure why... (0 Replies)
Discussion started by: arunkumar_mca
0 Replies

2. Shell Programming and Scripting

Zip data using Command

HI Guys, I using below command to zip data but in zip file i have entire path of source. zip $HOME/EM/ZIPData/All.tar.gz /vr/rt/on/mg/set/XM/Swor/xt/0300*.* In Zip file i have entire path vr/rt/on/mg/set/XM/Swor/xt/ I just want file data zip in may target location (2 Replies)
Discussion started by: pareshkp
2 Replies

3. Solaris

Need command to parse data

Hi Friends, I have data like below t064266 I want output into this format t064266 Data are space delimited and i want parse third column data. Thanks (9 Replies)
Discussion started by: Jagaat
9 Replies

4. UNIX for Dummies Questions & Answers

Join command: how to keep all fields in one data

Dear all, I 'd like to ask a question. I have two datasets: a.txt (only has one filed, call 'SNP'), b.txt( has thousands of fields, 1st field call 'SNP'). a.txt: rs9527 rs318567 rs12376 ... b.txt: rs167893 1 2 0 2 1 2 ... rs318567 2 0 2 1 2 0 ... rs12376 0 2 0 2 1 2 ... I... (2 Replies)
Discussion started by: forevertl
2 Replies

5. Shell Programming and Scripting

Type casting problem

hi guys, i m new to shell script.. i dont know how to type cast string into integers and i mention my problem below.. date="21091988" month=$((${date:2:2})) # extract the month from previous date variable temp=$(($month*23)) when i am trying to calculate the temp value i got the... (5 Replies)
Discussion started by: raadhaakrishnan
5 Replies

6. Programming

C++ type-casting a member variable in const methods

Is it permitted to type-cast a member variable passed in as a parameter in a member const method .. I am doing something like : in a return-type method () const { variable other = long(member variable) } this other assigned variable is not updating and I wonder if type-casting in such... (1 Reply)
Discussion started by: shriyer123
1 Replies

7. UNIX for Dummies Questions & Answers

Help with Data Sorting Command

Hi, I have a problem on data sorting, example my file as below: 123 123/789 aaa bbb ccc ddd (adf) 112 112/123 aaa bbb ccc (ade) 102 1a3/7g9 (adf)03 110 12b/129 aaa bbb ccc ddd fff(a8f)03 117 42f/8c9 aaa bbb ccc ddd (adf) 142 120/tyu fff... (7 Replies)
Discussion started by: 793589
7 Replies

8. UNIX for Advanced & Expert Users

How type casting works ?

I am having a doubt with type casting in C. Very often in network programming, we have something like this: char *data = ...; struct iphdr *ip = (struct iphdr *) data; where iphdr is define in netinet/ip.h. Let us say that the size of the content of held by 'data' is much more than... (1 Reply)
Discussion started by: radiatejava
1 Replies

9. Shell Programming and Scripting

Problem with type-casting in awk

Hi I'm trying to write a script which takes an integer as input and checks for files with size > input and displays it on screen. The code I've tried : echo 'Enter the min file size expected' read filesize du -ah <folder name> | awk -F: '$1>int(filesize) {print $1,$2)' is always... (28 Replies)
Discussion started by: vivek.bharadwaj
28 Replies

10. Shell Programming and Scripting

casting

Hi everyone, I was wondering how i could cast a floating value to an integer in csh Thanks (0 Replies)
Discussion started by: ROOZ
0 Replies
Login or Register to Ask a Question