Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a better way to parse the output of a command that produces a string with multiple columns than using awk '{print substr($0, 68)}'?

I run a CLI command that outputs various database values. One CLI command example is:

show attributes attr=0x1006e mh=0x12003ea | awk '{print substr($0, 68)}' | grep -v Value

The output looks like this:

Secure Domain

So this technique definitely works.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Without the awk command, and subsequent "grep -v Value" command the output looks like this:

Id    Name    Iid    Value
0x1006e Model_Name_Attr  Secure Domain

Where Id=0x1006e, Name=Model_Name_Attr, Iid=Blank column, Value=Secure Domain

The columns don’t match up in this "stackoverflow" website. sorry.

The awk command works because there are exactly 68 spaces until you reach the first word in the Value column, which is "Secure".

I can’t use awk 'NR==1 {next;}; {print $3}' because the output will simply be the word "Secure". The name has a space in between, and I need the entire Value of Secure Domain.

I tried various iterations of awk and cannot find a solution.

>Solution :

Remove the first two fields from the line, then print the rest of the line.

show attributes attr=0x1006e mh=0x12003ea | awk 'NR > 1 {$1 = $2 = ""; sub(/^ +/, ""); print}'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading