Format results in Bash

For example, I have test.txt with the following line:

L1~00~00~00~00~00~Test~122113~00~L2~This~Is~A~Sample~Data~L1~00~00~00~00~00~Test1~123456~00

I want to get “Test” and “Test1“, both are after L1~00~00~00~00~00~ with the following format.

Test, Test1

I already have this line in my bash script:

grep -oP 'L1(?:.[ws]*){5}.(K[ws]*)' < test.txt

But it returns a different format:

Test
Test1

How can I achieve this by adding sed in my script? I’m still a newbie. I hope somebody could help me. Thanks


Source: bash

Leave a Reply