replace time format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replace time format
# 8  
Old 04-25-2007
Quote:
Originally Posted by anbu23
Code:
sed "s/^\(\([^,][^,]*,\)\{5\}\)\([^:]*:[^:]*\):[^,]*,\(\([^,][^,]*,\)\{11\}\)\([^:]*:[^:]*\):[^,]*/\1\3,\4\6/" file

nothing change the output.
# 9  
Old 04-25-2007
Quote:
Originally Posted by happyv
Thx, but i forgot to mentioned that the field 18 also have the same issue, how can i fix it as well?
i will let you have a try. if the previous code i posted that modifies field 6 works for you, you can also do the same for field 18. just add another if statement.
# 10  
Old 04-25-2007
Quote:
Originally Posted by ghostdog74
i will let you have a try. if the previous code i posted that modifies field 6 works for you, you can also do the same for field 18. just add another if statement.
thx, but I don't know which value is to identify field 18?
# 11  
Old 04-25-2007
Quote:
Originally Posted by happyv
nothing change the output.
Code:
$ cat file
00001,CLIENT,Company,1218,N,1:04,35,0.211,0,0.211,1.155531,0:00,0,0,0,0,0,1:04,35,0.211,0,0.211,1.15 5531,foold store,USD
00001,CLIENT,Company,1219,N,23:36,42,21.127,0,21.127,115.700959,0:00,0,0,0,0,0,23:36,42,21.127,0,21. 127,115.700959,food store,USD
00001,CLIENT,Company,1220,N,26:17:00,43,38.091,0,38.091,208.603457,0:00,0,0,0,0,0,26:17:00,43,38.091 ,0,38.091,208.603457,food store,USD
00001,CLIENT,Company,1221,N,27:35:00,111,33.775,0,33.775,184.967099,0:00,0,0,0,0,0,27:35:00,111,33.7 75,0,33.775,184.967099, food store, US$
$
$
$ sed "s/^\(\([^,][^,]*,\)\{5\}\)\([^:]*:[^:]*\):[^,]*,\(\([^,][^,]*,\)\{11\}\)\([^:]*:[^:]*\):[^,]*/\1\3,\4\6/" file
00001,CLIENT,Company,1218,N,1:04,35,0.211,0,0.211,1.155531,0:00,0,0,0,0,0,1:04,35,0.211,0,0.211,1.15 5531,foold store,USD
00001,CLIENT,Company,1219,N,23:36,42,21.127,0,21.127,115.700959,0:00,0,0,0,0,0,23:36,42,21.127,0,21. 127,115.700959,food store,USD
00001,CLIENT,Company,1220,N,26:17,43,38.091,0,38.091,208.603457,0:00,0,0,0,0,0,26:17,43,38.091 ,0,38.091,208.603457,food store,USD
00001,CLIENT,Company,1221,N,27:35,111,33.775,0,33.775,184.967099,0:00,0,0,0,0,0,27:35,111,33.7 75,0,33.775,184.967099, food store, US$

# 12  
Old 04-25-2007
Quote:
Originally Posted by anbu23
Code:
$ cat file
00001,CLIENT,Company,1218,N,1:04,35,0.211,0,0.211,1.155531,0:00,0,0,0,0,0,1:04,35,0.211,0,0.211,1.15 5531,foold store,USD
00001,CLIENT,Company,1219,N,23:36,42,21.127,0,21.127,115.700959,0:00,0,0,0,0,0,23:36,42,21.127,0,21. 127,115.700959,food store,USD
00001,CLIENT,Company,1220,N,26:17:00,43,38.091,0,38.091,208.603457,0:00,0,0,0,0,0,26:17:00,43,38.091 ,0,38.091,208.603457,food store,USD
00001,CLIENT,Company,1221,N,27:35:00,111,33.775,0,33.775,184.967099,0:00,0,0,0,0,0,27:35:00,111,33.7 75,0,33.775,184.967099, food store, US$
$
$
$ sed "s/^\(\([^,][^,]*,\)\{5\}\)\([^:]*:[^:]*\):[^,]*,\(\([^,][^,]*,\)\{11\}\)\([^:]*:[^:]*\):[^,]*/\1\3,\4\6/" file
00001,CLIENT,Company,1218,N,1:04,35,0.211,0,0.211,1.155531,0:00,0,0,0,0,0,1:04,35,0.211,0,0.211,1.15 5531,foold store,USD
00001,CLIENT,Company,1219,N,23:36,42,21.127,0,21.127,115.700959,0:00,0,0,0,0,0,23:36,42,21.127,0,21. 127,115.700959,food store,USD
00001,CLIENT,Company,1220,N,26:17,43,38.091,0,38.091,208.603457,0:00,0,0,0,0,0,26:17,43,38.091 ,0,38.091,208.603457,food store,USD
00001,CLIENT,Company,1221,N,27:35,111,33.775,0,33.775,184.967099,0:00,0,0,0,0,0,27:35,111,33.7 75,0,33.775,184.967099, food store, US$

may be my unix not support "sed"

any other suggestion?
# 13  
Old 04-25-2007
HI
Did u Try this
cat file | awk -F, '{for(i=1;i<=NF;i++){if(i==6 || i==18){split($i,temp,":");printf("%s:%s,",temp[1],temp[2]);}else{printf("%s,",$i);}}}' > outfile

Thanks
Raghuram
# 14  
Old 04-25-2007
Quote:
Originally Posted by Raghuram.P
HI
Did u Try this
cat file | awk -F, '{for(i=1;i<=NF;i++){if(i==6 || i==18){split($i,temp,":");printf("%s:%s,",temp[1],temp[2]);}else{printf("%s,",$i);}}}' > outfile

Thanks
Raghuram
UUOC. there's no need for cat. and you forgot the newline. this is what i get
Code:
# awk -F, '{for(i=1;i<=NF;i++){if(i==6 || i==18){split($i,temp,":");printf("%s:%s,",temp[1],temp[2]);}else{printf("%s,",$i);}}} ' file
00001,CLIENT,Company,1218,N,1:04,35,0.211,0,0.211,1.155531,0:00,0,0,0,0,0,1:04,35,0.211,0,0.211,1.15 5531,foold store,USD,00001,CLIENT,Company,1219,N,23:36,42,21.127,0,21.127,115.700959,0:00,0,0,0,0,0,23:36,42,21.127,0,21. 127,115.700959,food store,USD,00001,CLIENT,Company,1220,N,26:17,43,38.091,0,38.091,208.603457,0:00,0,0,0,0,0,26:17,43,38.091 ,0,38.091,208.603457,food store,USD,00001,CLIENT,Company,1221,N,27:35,111,33.775,0,33.775,184.967099,0:00,0,0,0,0,0,27:35,111,33.7 75,0,33.775,184.967099, food store, US$,

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calculate Time diff in milli milliseconds(Time format : HH:MM:SS,NNN)

Hi All, I have one file which contains time for request and response. I want to calculate time difference in milliseconds for each line. This file can contain 10K lines. Sample file with 4 lines. for first line. Request Time: 15:23:45,255 Response Time: 15:23:45,258 Time diff... (6 Replies)
Discussion started by: Raza Ali
6 Replies

2. Programming

Find gaps in time data and replace missing time value and column 2 value by interpolation in awk

Dear all, I am kindly seeking assistance on the following issue. I am working with data that is sampled every 0.05 hours (that is 3 minutes intervals) here is a sample data from the file 5.00000 15.5030 5.05000 15.6680 5.10000 16.0100 5.15000 16.3450 5.20000 16.7120 5.25000... (4 Replies)
Discussion started by: malandisa
4 Replies

3. HP-UX

DATE and TIME format help in HP-UX

Hello, I have date format as shown in red color below Fri, Sep 12, 2012 08:38:05 PM Can anyone help me with command to change this format to yyyy-mm-dd and HH:MM:SS Note: Time should be in 24 hours format I really appreciate your help!! Thanks, Elavarasan (4 Replies)
Discussion started by: Elavarasan
4 Replies

4. Shell Programming and Scripting

time format

Hello Guys. I have copied the following from the time man pages time -f "%E real,%U user,%S sys" ls -Fs But I am getting -f: command not found Regards (3 Replies)
Discussion started by: fdc2suxs
3 Replies

5. Shell Programming and Scripting

Replace a format

I have a file which contains 1.3.6.1.4.1.637.61.1.35.10.19.1.10 1.3.6.1.4.1.637.61.1.35.15.3.1.4 Now i want to replace the last occurance of ".1." to ":" The output should look like 1.3.6.1.4.1.637.61.1.35.10.19:10 1.3.6.1.4.1.637.61.1.35.15.3:4 (6 Replies)
Discussion started by: LavanyaP
6 Replies

6. Shell Programming and Scripting

perl time format

Hay guys, I used time::local module. But i can't get my proper answer from this. I want to extract two time for tomorrow start time and end time. In my code i just hard coded this. But it's not running for every day na. I need to create these time from any function or module. my... (2 Replies)
Discussion started by: pritish.sas
2 Replies

7. Shell Programming and Scripting

Convert Epoch time format to normal date time format in the same file

I have a file named "suspected" with series of line like these : {'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''} {'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Discussion started by: rk4k
3 Replies

8. Shell Programming and Scripting

help in time format

how to grep 30 mins from starting time of script let for example,script runs at 02:00am....i want to grep from 01.30 till 02:00 ------------------------------------------------------------------- how to achive this in a k-shell script ? (3 Replies)
Discussion started by: ali560045
3 Replies

9. Shell Programming and Scripting

time format..

HI.. I have some files...when doing "ls -l" its like this.. -rwxr-xr-x 1 e2e e2e 747 Aug 30 15:18 abc.txt how can I get the number YYYYMMDD from this...( since I need to compare this number with some other value..) with the help of date/awk/sed/epoch or whatever u... (1 Reply)
Discussion started by: clx
1 Replies
Login or Register to Ask a Question