1754274 Members
3369 Online
108813 Solutions
New Discussion юеВ

Awk Query

 
SOLVED
Go to solution
user57
Occasional Advisor

Awk Query

Could someone please assist with the below. I am attempting to print pairs of devices which are colon seperated.

Each A and B device is associated with a "V" adapter.

If there are no devices associated with a "V" adapter it is to be ignored.


input:

V0:A1:B1:A2:B2
V1: :
V2:A1:B1:A2:B2:A3:B3
V3:A1:B1:A2:B2:A3:B3:A4:B4


Desired output:

V0:A1:B1
V0:A2:B2
V2:A1:B1
V2:A2:B2
V2:A3:B3
V3:A1:B1
V3:A2:B2
V3:A3:B3
V3:A4:B4

5 REPLIES 5
James R. Ferguson
Acclaimed Contributor
Solution

Re: Awk Query

Hi:

# awk -F: 'BEGIN{OFS=":"};{V=$1;for (i=2;i<=NF;i+=2) {print V,$i,$(i+1)}}' file

Regards!

...JRF...
user57
Occasional Advisor

Re: Awk Query

Thanks
user57
Occasional Advisor

Re: Awk Query

Solution provided - closing
James R. Ferguson
Acclaimed Contributor

Re: Awk Query

Hi (again):

I see that you are new to this Forum. Welcome!

That said, please read the link below about points. Points are not only a way of saying "thanks!" but bread-crumbs for future trollers to find the tastiest (most applicable) solution:

http://forums.itrc.hp.com/service/forums/helptips.do?#28

Regards!

...JRF...
melvyn burnard
Honored Contributor

Re: Awk Query

Also, in future do not open two threads with the same subject.
My initial view was these were duplicate, and I was about to delete one.
My house is the bank's, my money the wife's, But my opinions belong to me, not HP!