Making times mysql compliant


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Making times mysql compliant
# 1  
Old 01-21-2012
Making times mysql compliant

I have the following file:
Code:
Loc1,20080102,230100,0.5617,0.5617
Loc1,20080102,230400,0.5616,0.5616
Loc1,20080102,230700,0.5615,0.5615

Then I use the following code to turn the third column into something which to mysql has the time datatype:

Code:
sed -i '' -e "s#,\(..\)\(..\)\(..\),#,\1:\2:\3,#" file.dat

It correctly transforms the third column into times:

Code:
Loc1,20080102,23:01:00,0.5617,0.5617
Loc1,20080102,23:04:00,0.5616,0.5616
Loc1,20080102,23:07:00,0.5615,0.5615

What I am wondering is why the fourth column is unaffected, since it also has 6 characters and has a comma (,) on both sides. Is because of the decimal point (.)?
# 2  
Old 01-21-2012
It is because your sed statement is executed only once per line, because, there is no flag after the last # (like e.g. g). In this case even if there were a flag g, then there would still only be one match, since the last comma was already part of the first match, so it cannot be part of the second match..

If you left out one of the commas for example then it would happen everywhere with the g flag.:

Code:
$ echo "Loc1,20080102,230100,0.5617,0.5617" | sed  -e "s#,\(..\)\(..\)\(..\)#,\1:\2:\3#g"
Loc1,20:08:0102,23:01:00,0.:56:17,0.:56:17

# 3  
Old 01-21-2012
Makes sense, thanks.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. OS X (Apple)

Generate a random number in a fully POSIX compliant shell, 'dash'...

Hi all... Apologies for any typos, etc... This took a while but it didn't beat me... Although there are many methods of generating random numbers in a POSIX shell this uses integer maths and a simple C source to create an executable to get epoch to microseconds accuracy if it is needed. I take... (8 Replies)
Discussion started by: wisecracker
8 Replies

2. Shell Programming and Scripting

Q: Is SQRT(n) possible in a POSIX compliant shell? A: Yes within limits.

Hi all... This is just a fun project to see if it is possible to get a square root of a positive integer from 1 to 9200000 to 6 decimal places on a 64 bit architecture machine. It is coded around dash and the results show the values from 0 to 10000. Complex numbers can easily be catered for by... (3 Replies)
Discussion started by: wisecracker
3 Replies

3. Shell Programming and Scripting

Logical expression in POSIX compliant Korn Shell

Hi, i want to check if a variable var1 is not a or b or c pseudo code: If NOT (var1 = a or var1 = b or var1 = c) then ... fi I want to use POSIX complaint Korn shell, and for string comparison For the following code, logical.sh #!/usr/bin/ksh var="j" echo "Var : $var" if ! { || ||... (12 Replies)
Discussion started by: ysrini
12 Replies

4. Programming

Problem with implementing the times() function in C (struct tms times return zero/negative values)

Hello, i'm trying to implement the times() function and i'm programming in C. I'm using the "struct tms" structure which consists of the fields: The tms_utime structure member is the CPU time charged for the execution of user instructions of the calling process. The tms_stime structure... (1 Reply)
Discussion started by: g_p
1 Replies

5. Programming

Is gcc compliant with the C++ standards

Hello Friends, I am a newbie and have started using different compilers and tools to make myself familiar with their workings. I wanted to know that how compliant is gcc with the C++ standards. It is pretty obvious that no compiler is close to being completely compliant, but if there are some... (7 Replies)
Discussion started by: hthapar
7 Replies

6. AIX

how would you know your server was rebooted 3 times or 5 times

Is there such location or command to know how many times did you reboot your server in that particular day?in AIX. (3 Replies)
Discussion started by: kenshinhimura
3 Replies
Login or Register to Ask a Question