Reputation: 12366
I have a Java log file and want to transform it using awk
. The file has following record structure:
filename:date time [level] (thread) message
Here is an example line:
2018-01-19-19.prod.com.gz:2018-01-19 19:14:29,964 [INFO] (Runner for {AccountId: ‘1234’, JobFlowId: ‘abcd’, TaskId: ‘4321’, Type: ‘TestType’}) com.damluar.AbstractObjectCache: Found unexpired object in local cache for key: testkey
The resulting file needs to have fields and have \t as separators:
If I use whitespace or :
as separator then content of thread
and message
fields got split too. What would be the best way to process it?
Upvotes: 0
Views: 107
Reputation: 195079
sed 's/:/:\t/;s/\[/\t&/;s/\]/&\t/;s/)/)\t/' log
the above line will separate the required fields by tab
. If you want to output them, you can pipe it to awk to check:
echo "yourExample"||sed 's/:/:\t/;s/\[/\t&/;s/\]/&\t/;s/)/)\t/'|awk -F '\t' '{for(i=1;i<=NF;i++)print $i}'
2018-01-19-19.prod.com.gz:
2018-01-19 19:14:29,964
[INFO]
(Runner for {AccountId: ‘1234’, JobFlowId: ‘abcd’, TaskId: ‘4321’, Type: ‘TestType’})
com.damluar.AbstractObjectCache: Found unexpired object in local cache for key: testkey
Upvotes: 2