mardi 15 décembre 2020

How to make sequential lines come in columns based on condition?

Could anyone help to get desired output like mentioned below?

❯ cat example.txt
hostname a-b-c
services Apache
hostname d-e-f
services Python
hostname g-h-i
vmhostname u-v-w
vmhostname x-y-z

I would like to get output like below

a-b-c Apache
d-e-f Python
g-h-i No services
u-v-w No services
x-y-z No services

I have used awk but getting different output.

❯ cat example.txt | awk 'NR%2{printf $0" ";next;}1'
hostname a-b-c services Apache
hostname d-e-f services Python
hostname g-h-i vmhostname u-v-w
vmhostname x-y-z %

Aucun commentaire:

Enregistrer un commentaire