Parse output of bash tool --> only get strings with matching pattern (with nothing between)

1

I use a can-discovery tool which gives me an output like this one below:

-------------------
CARING CARIBOU v0.3
-------------------

Loaded module 'uds'

Sending Diagnostic Session Control to 0x0710
  Verifying potential response from 0x0710
    Resending 0x710...  Success
Found diagnostics server listening at 0x0710, response at 0x077a
Sending Diagnostic Session Control to 0x07df
  Verifying potential response from 0x07df
    Resending 0x7df...  Success
Found diagnostics server listening at 0x07df, response at 0x077a
Sending Diagnostic Session Control to 0x07e0
  Verifying potential response from 0x07e0
    Resending 0x7e0...  Success
Found diagnostics server listening at 0x07e0, response at 0x077a
Sending Diagnostic Session Control to 0x07ff

Identified diagnostics:

+------------+------------+
| CLIENT ID  | SERVER ID  |
+------------+------------+
| 0x00000710 | 0x0000077a |
| 0x000007df | 0x0000077a |
| 0x000007e0 | 0x0000077a |
+------------+------------+

Now I want to process the results in my Java Script application and save it to my database as Client and Server IDs. But to do this I need to parse this output above to get just the IDs as client and server IDs. The first step now would be to get the Hex IDs fromt he output and specify if Client or Server. The problem is I dont know grep/awk/sed good enough to think of any bash command to solve my problem. Would be great if somebody could help me a little bit out :)

I tried all sorts of grep commands like grep 0x000 disc_log_temp.txt , also with different options like -w -x -o ect.

With this commands I get outputs like this one:

Sending Diagnostic Session Control to 0x0710
| 0x00000710 | 0x0000077a |
| 0x000007df | 0x0000077a |
| 0x000007e0 | 0x0000077a |

But I need just the single ID strings and also dont understand why my grep displays the first line....

Now if somebody could tell my how I can manage to get just the IDs and also know which ones are Client and which ones are Server IDs it would be really great. Thank you very much in advance.

regex
bash
shell
grep
asked on Stack Overflow Jul 16, 2019 by x13

1 Answer

0

If you use awk, the first field of the line you want is "|" and the number of fields is 5. I'm not sure how you want it formatted, it should be easy to modify though.

awk '$1=="|"&&NF==5{print "client: " $2 ", server: " $4}' disc_log_temp.txt
answered on Stack Overflow Jul 16, 2019 by Dabombber

User contributions licensed under CC BY-SA 3.0