I am dealing with some app log, see example below:
22:16:13.601 [192.168.1.183] ClientSession(905)--Connection(5)--SELECT GETDATE()
22:16:13.632 [192.168.1.183] ClientSession(158)--Connection(5)--SELECT 1
22:16:13.632 [192.168.1.175] ClientSession(848)--Connection(6735)--SELECT 1
So far I needed to collect certain column from it, such as get all the sql commands:
$ cut -d'-' -f5 xx
SELECT GETDATE()
SELECT 1
SELECT 1
or get all the session ids
$ cut -d'(' -f2 xx|cut -d')' -f1
905
158
848
So, cut helps me with this sort of things. But in some cases I need to get several columns at once, such as get the timestamp and the sql command
such as
22:16:13.601 SELECT GETDATE()
22:16:13.632 SELECT 1
22:16:13.632 SELECT 1
For this I am using awk, but it seems quite cumbersome and I understand that if I have known enough regexp then sed would be a quick and easy solution here, but I don't.
My attempt to use sed for getting time and sql command
sed 's/\([0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9]\)\(.*--\)\(*\)/\1 \3/' log.txt
outputs whole thing, as if I did cat it
Please help me with sed solution.