我在Linux服务器上有一些应用程序日志数据,如下所示,
2015-10-09 08:16:40,692 28456 INFO Demodb openerp.addons.service_logger.service_logger: 1 res.partner.fields_view_get ([], {'view_id': 127, 'toolbar': False, 'context': {'
lang': 'en_US', 'tz': 'Europe/Brussels', 'uid': 1, 'active_model': 'res.partner', 'params': {'action': 60}, 'search_default_customer': 1}, 'view_type': 'search'})
2015-10-09 08:16:40,701 28456 INFO Demodb openerp.addons.service_logger.service_logger: 1 res.partner.fields_view_get ([], {'view_id': 128, 'toolbar': True, 'context': {'l
ang': 'en_US', 'tz': 'Europe/Brussels', 'uid': 1, 'active_model': 'res.partner', 'params': {'action': 60}, 'search_default_customer': 1}, 'view_type': 'kanban'})
我想将其输出为csv格式,(基本上来自'([]'它可以是批处理)
2015-10-09,08:16:40,701,28456,INFO,Demodb openerp.addons.service_logger.service_logger:,1,res.partner.fields_view_get,([],{'view_id': 128,'toolbar': True,'context':,{'l
ang':'en_US','tz': 'Europe/Brussels', 'uid': 1, 'active_model': 'res.partner', 'params': {'action': 60}, 'search_default_customer': 1}, 'view_type': 'kanban'})
任何输入都会有所帮助,
答案 0 :(得分:0)
这会用逗号替换所有空格,直到第一次出现([]
:
sed -e 'h;s/.*(\[\]//;x;s/\s\+(\[\].*//g;s/\s\+/,/g;G;s/\n/,([]/'
说明:
h # copy line to hold
s/.*(\[\]// # remove everything before ([]
x # swap unchanged line back from hold, put part after ([] to hold
s/\s\+(\[\].*//g # remove everything after ([]
s/\s\+/,/g # do work, that is change spaces to commas
G # glue the two parts together, with a newline inbetween
s/\n/,([]/ # put the ([]-marker back between the two parts