I am working on extracting service objects (ports/protocols) from a large router configuration file. Using awk, I would like to be able to take unique instances of $5 and print them on one line, with the various values in $7 printed after the unique instance of $5 separated by commas.

Input data:

```
set resources group port-group ServiceA port '1'
set resources group port-group ServiceA port '2'
set resources group port-group ServiceA port '3'
set resources group port-group ServiceB port '10'
set resources group port-group ServiceA port '1'
set resources group port-group ServiceA port '2'
set resources group port-group ServiceA port '3'
set resources group port-group ServiceB port '10'
set resources group port-group ServiceB port '20'
set resources group port-group ServiceC port '30'
set resources group port-group ServiceC port '40'
set resources group port-group ServiceD port '50'
set resources group port-group ServiceD port '5050'
set resources group port-group ServiceD port '60'
set resources group port-group ServiceD port '65'
set resources group port-group ServiceD port '66'
set resources group port-group ServiceD port '89'

```

Desired Output:

```
set resources group port-group ServiceA port 1, 2, 3
set resources group port-group ServiceB port 10, 20
set resources group port-group ServiceC port 30, 40
set resources group port-group ServiceD port 50, 5050, 60, 65, 66, 89

```

So far my attempts at making awk statements have not been fruitful.

What I've tried (it's part of a script so that's why there are CR.)

```
awk '{
gsub(/[:\47]/,"")}; i=!seen[$5]++; {print i,$7 } ' inputfile.txt

```

This gives me the following output:

```
set resources group port-group ServiceA port 1
1 1
0 2
0 3
set resources group port-group ServiceB port 8
1 8
0 1
0 2
0 3
0 8
0 3
set resources group port-group ServiceC port 2
1 2
0 3
set resources group port-group ServiceD port 8
1 8
0 5050
0 3
0 83
0 1
0 2
0 990
0 3000
0 3001
0 3002
0 3003

```

I'm assuming I will have to use a multidimensional array with a for loop to accomplish this, but I'm stuck. Any help is appreciated!