Converting tomcat logs to CSV using sed [closed]
Using sed
$ sed 's/.*\[\(.*\)]/\1/;1iDateandTime, AccountID, UserID, ClientIP ' file
DateandTime, AccountID, UserID, ClientIP
1587566256,49294,"[email protected]",3237159933,1,0,0,3,"2314","https",443,2899903330,"https://googleads.g.doubleclick.net/pagead/ads",0,"","","","","1 - Default Policy","","googleads.g.doubleclick.net","GET",4,0,5
1587566256,49294,"[email protected]",3237159933,1,0,0,3,"2339,37788","http",80,387803624,"http://ping.citrix.com",0,"","","","","3 - Extended Policy High","","ping.citrix.com","HEAD",3,0,4
.*\[
- Exclude everything up to the last [
square bracket.
\(.*\)]
- Include everything within the parenthesis up to the last ]
square bracket
\1
- Return with back reference the contents stored inside the parenthesis
1i
- Insert on line 1