Help needed in replace

Hi,

I have a pipe delimited file. I need to change the timestamp in the second field in all the records to a specific value. can you please let me know how i can do it?

sample file with 2 reocrds. The time i need to change is in red below.

Please let me know how I can change only the time in the second field for all the records in the file.

sed 's/\([^|]\+|[^ ]\+ \)[^|]\+\(.*\)/\1SOME_VALUE\2/' input_file

where SOME_VALUE is your intended value.

neked@mercurial:~$ echo "234876119|2008-09-23 10:29:31|9999-12-31|1012|1089|I|1|2008-09-23 10:29:31.000336||" \
> | sed 's/\([^|]\+|[^ ]\+ \)[^|]\+\(.*\)/\1SOME_VALUE\2/'

234876119|2008-09-23 SOME_VALUE|9999-12-31|1012|1089|I|1|2008-09-23 10:29:31.000336||

With awk:

awk 'BEGIN{FS=OFS="|"}{split($2,s," ");$2=s[1]" NEW_VALUE"}1' file

Regards

Thanks Franklin. This works like magic. But if I want to replace the whole field with a different value what would be the syntax?

Neked,

For some reason the code doesnt seem to work for me. Thanks though.

That's a pretty cool implementation, but one question to you, what does the '1' at the end of the awk directive do? I notice your implementation will not work without it...

Using Franklin's technique:

awk 'BEGIN{FS=OFS="|"}{$2="NEW_VALUE"}1' test

Thanks So much Neked and Franklin.

awk evaluates the 1 as true and the prints the entire line by default, similar to {print $0}.

Regards