这是一个名为'colors.txt'的文件中的RGB值列表
255 222 0
101 153 255
255 153 0
13 112 84
13 112 84
255 222 0
13 112 84
9 112 84
Run Code Online (Sandbox Code Playgroud)
我可以使用awk数组从文件中获取5个独特的RGB组合
awk '{arr[($1","$2","$3)]} END {for (i in arr) print i}' colors.txt
Run Code Online (Sandbox Code Playgroud)
这给出了:
9,112,84
255,222,0
13,112,84
255,153,0
101,153,255
Run Code Online (Sandbox Code Playgroud)
请注意,这些不是它们在输入文件中的顺序.但是,这个命令
awk 'arr[($1","$2","$3)]++==0 {print ($1","$2","$3)}' colors.txt
255,222,0
101,153,255
255,153,0
13,112,84
9,112,84
Run Code Online (Sandbox Code Playgroud)