I'm processing this data in Python, which has first four fields separated by "|", Fifth field onwards separated by space.
VER:1|long=|lat=|device=D3052|eventid=31007311 status=Active time=1528496310749 priority=1 desitnationHost= group=cluster1
VER:1|long=|lat=|device=D3010|eventid=31007312 status=Active time=1528496310765 priority=1 desitnationHost= group=cluster1
VER:1|long=|lat=|device=D3094|eventid=31007313 status=Active time=1528496315380 priority=1 desitnationHost= group=cluster1
VER:1|long=|lat=|device=D3052|eventid=31007314 status=Active time=1528496317513 priority=1 desitnationHost= group=cluster1
VER:1|long=|lat=|device=D3010|eventid=31007315 status=Active time=1528496329604 priority=1 desitnationHost= group=cluster1
Time field contains epoch time value, need to update this value by 1 year
This data is contained in multiple text files in a directory which needs to be processed by reading each text file, line by line.
My approach in Python -
#import required python library
import os
import re
#read a text file (later need to loop through multiple text files)
h = open('C:/directory/new_1.txt', 'r')
# Reading from the file
content = h.readlines()
# Iterating through the content
# Of the file
for line in content:
milli_second_in_year = 31536000000
l = re.sub(r'time=(\d+)',r'\1d','milli_second_in_year')
print(l)
In my above approach, I cannot sum up extracted time value with the 'milli_second_in_year'
I tried below changes, but unable to get the expected output -
for line in content:
m = re.search(r'time=(\d+)',line)
match = m.group(1)
match = int(match)+31536000000
print(match)
getting the desired time value, unable to write back to the file again
Expected output (updated time values) -
VER:1|long=|lat=|device=D3052|eventid=31007311 status=Active time=1560032310749 priority=1 desitnationHost= group=cluster1
VER:1|long=|lat=|device=D3010|eventid=31007312 status=Active time=1560032310765 priority=1 desitnationHost= group=cluster1
VER:1|long=|lat=|device=D3094|eventid=31007313 status=Active time=1560032315380 priority=1 desitnationHost= group=cluster1
VER:1|long=|lat=|device=D3052|eventid=31007314 status=Active time=1560032317513 priority=1 desitnationHost= group=cluster1
VER:1|long=|lat=|device=D3010|eventid=31007315 status=Active time=1560032329604 priority=1 desitnationHost= group=cluster1