Change the seconds value in date column

Hello,

I have a file with below contents and need to set seconds value to 00 (as you can see few time stamps are with 01 seconds)

18:16:00        8192    7301    89      11
18:21:00        8192    7305    89      11
18:26:00        8192    7306    89      11
18:31:00        8192    7306    89      11
18:36:00        8192    7306    89      11
18:41:01        8192    7306    89      11
18:46:01        8192    7306    89      11
18:51:00        8192    7306    89      11
18:56:01        8192    7306    89      11
19:01:00        8192    7301    89      11
19:06:01        8192    7306    89      11
19:11:00        8192    7306    89      11
19:16:00        8192    7306    89      11
19:21:01        8192    7308    89      11
19:26:00        8192    7306    89      11
19:31:00        8192    7306    89      11
19:36:00        8192    7306    89      11
19:41:00        8192    7306    89      11

I tried sed 's/:01$/:00/g' but it works only if I have one column with time stamps.

Please advise
Thank you,

Drop the EOL indicator, and don't use the g option:

sed 's/:01 /:00 /' file

You said it only works with one column with timestamps, but as RudiC said, your code only works if there is only one column with timestamps and that timestamp is at the end of the line. RudiC's code works for one timestamp anywhere on a line except at the end of a line (and won't work if you have tabs as field separators instead of spaces).

As long as you have a version of sed that conforms to the standards, the following should work no matter how many timestamps you have on a line, no matter where they are placed on a line, and no matter what field separators you use:

sed 's/\([0-2][0-9]:[0-5][0-9]:\)[0-9][0-9]/\100/g' file

If file contains:

18:16:00        8192    7301    89      11
18:21:00        8192    7305    89      11
18:26:00        8192    7306    89      11
18:31:00        8192    7306    89      11
18:36:00        8192    7306    89      11
18:41:01        8192    7306    89      11
18:46:01        8192    7306    89      11
18:51:00        8192    7306    89      11
18:56:01        8192    7306    89      11
19:01:00        8192    7301    89      11
19:06:01        8192    7306    89      11
19:11:00        8192    7306    89      11
19:16:00        8192    7306    89      11
19:21:01        8192    7308    89      11
19:26:00        8192    7306    89      11
19:31:00        8192    7306    89      11
19:36:00        8192    7306    89      11
19:41:00        8192    7306    89      11
01:02:03	04:05:06	07:08:09	10:11:12	13:14:15

the output produced is:

18:16:00        8192    7301    89      11
18:21:00        8192    7305    89      11
18:26:00        8192    7306    89      11
18:31:00        8192    7306    89      11
18:36:00        8192    7306    89      11
18:41:00        8192    7306    89      11
18:46:00        8192    7306    89      11
18:51:00        8192    7306    89      11
18:56:00        8192    7306    89      11
19:01:00        8192    7301    89      11
19:06:00        8192    7306    89      11
19:11:00        8192    7306    89      11
19:16:00        8192    7306    89      11
19:21:00        8192    7308    89      11
19:26:00        8192    7306    89      11
19:31:00        8192    7306    89      11
19:36:00        8192    7306    89      11
19:41:00        8192    7306    89      11
01:02:00	04:05:00	07:08:00	10:11:00	13:14:00

Thanks RudiC and Don Cragun.

@Don Cragun - You are right. RudiC's solution did not work. I'm running on AIX 6 ksh.

Your solution worked great. In your solution, the one within () would remain be unchanged by sed? instead only the latter part replaced? also what does \1 (before 00) do?

Pl explain, thank you again!

Do you have TABs as field separators?

The \1 prints what matched within the first ( ).

Given the spacing between fields in the sample input, I was guessing that tabs could have been converted to spaces in the copy and paste process. redder will have to let us know whether the real data has spaces, tabs, or a mix.

I chose a BRE that would work either way.

To expand on what MadeInGermany said: \digit expands to the string that was matched by the BRE between the \( and the matching \) where the digit (1 through 9) refers to the 1st through the 9th \( to indicate which matched expression is to be included in the replacement text. In the expression I gave, \1 expands to HH:MM: from the matched timestamp. So \100 expands to the matched hours and minutes with the seconds replaced by 00 .