bash - Shell Script to replace multiple instances of unix timestamps in a file -


i have file has data similar following:

>       <element      >       stream="12" >       target_trans="133106" >       trans="48467" >       filemodtime="1358349304" >       type="1" >       eol="0" >       user_id="33" />   <element      >       stream="14" >       target_trans="133106" >       trans="48467" >       filemodtime="1358539304" >       type="1" >       eol="0" >       user_id="33" />   <element      >       stream="11" >       target_trans="133113" >       trans="48467" >       filemodtime="1158539204" >       type="1" >       eol="0" >       user_id="33" />   <element      >       stream="11" >       target_trans="133106" >       trans="48467" >       filemodtime="1358129304" >       type="1" >       eol="0" >       user_id="33" /> 

i need go through file, find instances of filemodtime unix timestamp , replace value there human readable date , timestamp.

i know command change date. im not sure how actual grepping through file, extracting epoch timestamp , passing conversion command.

any appreciated.

something should do:

awk '/filemodtime/{   split($0, a, "=")   gsub(/"/, "", a[2])   sub(/[0-9]+/, strftime("%f %t", a[2]), $0) }1' input.xml 

however, in general it's not idea process xml data line-by-line. might better off using actual xml parser.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -