Sonicarrow
Sonicarrow

Reputation: 73

Need help cleaning up a log file with bash

06/25 11:07:24 [INFO] *** CONTROL OUT bytes: 020106/25 11:07:24 [INFO]*** CONTROL IN bytes:080205063D715EB8F4740400200000FFE7010002000000000000000000000006/25 11:07:24 [INFO] hardware revision: 006/25 11:07:24 [INFO] dongle firmware version: 2.506/25 11:07:24 [INFO] dongle bluetooth address: 06:3D:71:5E:B8:F406/25 11:07:24 [INFO] CLIENT: [06/25 11:07:24] Dongle | Version|"majorVersion":2,"minorVersion":5,"deviceAddr":6,61,113,94,184,244],"flashEraseTime":1140,"firmwareStartAddress":8192,"firmwareEndAddress":124927,"ccIC":2,"hardwareRevision":0,"revision":0}06/25 11:07:24 [INFO] CLIENT: [06/25 11:07:24] Dongle | Set Power Level | 506/25 11:07:24 [INFO] Received message from client.06/25 11:07:24 [INFO] *** CONTROL OUT bytes: 020D050

So I want to clean this up by putting each command/section on a new line, like this,

06/25 11:07:24 [INFO] CLIENT: [06/25 11:07:24] Dongle | Set Power Level | 5
06/25 11:07:24 [INFO] Received message from client.
06/25 11:07:24 [INFO] *** CONTROL OUT bytes: 020D050

but I'm not really sure where to go from here.

Upvotes: 2

Views: 68

Answers (2)

amit_g
amit_g

Reputation: 31250

awk 'BEGIN { RS="[0-9]{2}/[0-9]{2}"; } { print rt $0; rt = RT; }' < filename

Upvotes: 2

Eugeniu Rosca
Eugeniu Rosca

Reputation: 5305

UPDATE: Comments merged in the answer! Thanks, Charles Duffy and pabouk.

Assuming your string is in filename:

# bound to GNU sed, because of '-r/--regexp-extended'
sed -r 's:[0-9]{2}/[0-9]{2}:\n&:g' <filename

# without '-r':
sed 's:[0-9][0-9]/[0-9][0-9]:\n&:g' <filename

For better safety, pabouk suggests matching a longer pattern:

sed -r 's@[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}@\n&@g' <filename

Upvotes: 4

Related Questions