A single string consisting of comma-separated pairs in the format <key>=<value>
, like
ABC=https://host:443/topic1,DEF=https://host:443/topic1,GHI=https://host:443/topic3,JKL=https://host:443/topic3
must be converted to a line containing the unique set (for which the order does not matter) of values, separated by an empty space, i. e.:
https://host:443/topic1 https://host:443/topic3
via an Awk program.
The background idea is to convert one variant of CLI-arguments into another one in a shell script, like:
#!/bin/bash
all_args="ABC=https://host:443/topic1,DEF=https://host1:443/topic1,GHI=https://host:443/topic3,JKL=https://host:443/topic3"
command1 $all_args
command2 $(echo $all_args | awk -f extractor.awk)
The solution:
BEGIN { FS="," }
{
for ( i = 1; i <= NF; i++) {
split($i, arr, "=")
vals[arr[2]] = arr[2]
}
for (v in vals) printf(v " ")
}