Skip to content
Advertisement

formatting the output with sed command

I need your help… I got this kind of text:

JavaScript

and the output I need is (first and second column and socialSecurityNumber OR tng-customer-id):

JavaScript

So the question is … is it possible to solve this issue with sed command? I need the OR option here.

If I try to do it separately, firstly, find the socialSecurityNumber, I get this:

JavaScript

secondly, find the tng-customer-id, I get this:

JavaScript

So, if you can see, in the first example when the socialSecurityNumber is not found in two last lines it just prints them out. In the second example the same situation …

When I try to complect my sed command with OR operator I get this output, which is completely wrong:

JavaScript

So … what I’m doing wrong?

Advertisement

Answer

Use this sed:

JavaScript

Test:

JavaScript

From your command:

JavaScript

I have removed .* in each grouping which is grouped by outer single group. So that, the unmatched string won’t be grouped.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement