There are lines:

vmwVmMAC.43 0:50:56:96:5b:63 vmwVmMAC.44 0:50:56:96:4d:20 vmwVmMAC.45 0:50:56:b7:1b:32 vmwVmMAC.45 0:50:56:b7:2b:4b 

How to convert them to this form by combining the second fields when the first fields match:

 vmwVmMAC.43 0:50:56:96:5b:63 vmwVmMAC.44 0:50:56:96:4d:20 vmwVmMAC.45 0:50:56:b7:1b:32 , 0:50:56:b7:2b:4b 

A tool is required that can pass source lines through a pipe:

 $ cat file | merge --by -f1 -d'\t' 
  • one
    @alexanderbarakin For the first time I see that pipe someone called a pipe in this context. - αλεχολυτ
  • @alexolut, suggest a better translation. - aleksandr barakin
  • 3
    @alexanderbarakin channel or conveyor, for example. - αλεχολυτ
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky
  • it was translated by Alexander from a very shabby rugish :) I was sure that there was a way to do this with one pipeline with some sed :) But it works so well, it will do for my tasks, thanks - Friend

1 answer 1

you can do this, for example, using a small program for the awk interpreter:

 BEGIN { OFS=""; } { if (NR==1) { k=""; } else { if (n==$1) { if (k!="") k=k" , "; } else { print n,"\t",k; k=""; } } n=$1; $1=""; k=k$0; } END { print n,"\t",k; } 

You can call this program, saving it in the .awk file, as follows:

 $ awk -f программа.awk file 

or so:

 $ cat file | awk -f программа.awk 

work example:

 $ cat file 1 a 1 b 2 c 3 d 3 e 3 f $ cat file | awk -f программа.awk 1 a , b 2 c 3 d , e , f