Skip to content
Advertisement

How to add text at the end of each line after skipping Last N characters

I’m on Linux command line and I have log file with following content

Subscription Service Shutdown at 9:59PM UTC
Subscription Service Restarted at 11:57PM UTC

I want to add date before Time Stamp for every line

Subscription Service Shutdown at 01 Oct 2016 9:59PM UTC
Subscription Service Restarted at 01 Oct 2016 11:57PM UTC

Advertisement

Answer

Something like this:

sed -r “s/([0-9]+{1}:[0-9]+{1}[A-Z]{2}.*$)/01 Oct 2016 1/g” test.txt > new.txt

Where text.txt is your log file and “01 Oct 2016 ” is your text and the 1 is the time inserted back in from the group match.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement