Skip to main content
added output formatting
Source Link
steeldriver
  • 83.9k
  • 12
  • 124
  • 175
$ awk -F"/" '!seen[$1]++ {print $1}' findint.txt 
Eth1
Eth101
Eth103
Gi0

To get the output all in one comma-separated line, you could set the output separator ORS to , however you'd need to make a special case for the the last value; a simpler way is to pipe the output of awk to paste:

awk -F"/" '!seen[$1]++ {print $1}' findint.txt | paste -sd,
$ awk -F"/" '!seen[$1]++ {print $1}' findint.txt 
Eth1
Eth101
Eth103
Gi0
$ awk -F"/" '!seen[$1]++ {print $1}' findint.txt 
Eth1
Eth101
Eth103
Gi0

To get the output all in one comma-separated line, you could set the output separator ORS to , however you'd need to make a special case for the the last value; a simpler way is to pipe the output of awk to paste:

awk -F"/" '!seen[$1]++ {print $1}' findint.txt | paste -sd,
Source Link
steeldriver
  • 83.9k
  • 12
  • 124
  • 175

$ awk -F"/" '!seen[$1]++ {print $1}' findint.txt 
Eth1
Eth101
Eth103
Gi0