Calvin Calvin - 1 year ago 133
Linux Question

Format timestamp output using sed

I'm new to Linux in general, I want to change the format of my log file using sed command:

Current format:

2016-09-27file.txt::2016-09-27 18:00:00

Expected format:


How should I write the sed command?


Answer Source

Following shows how to do it on a single line:

echo "2016-09-27file.txt::2016-09-27 18:00:00" | sed 's/\([0-9]*\)-\([0-9]*\)-\([0-9]*\) /\1\/\2\/\3-/'

The regexp part matches for the date part that you want to replace, which is also split-ed into sub-expression to make those part referable on replacement part.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download