Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个文件
cat file ab,12 ab,45 ab,23 bh,32 bl,12 ab,10 bh,13
并且该文件与第一个参数有重复的行
我需要我的输出具有以逗号分隔的特定参数的唯一值
例如输出
cat file ab,12 bh,32 bl,12
以下命令适用于您的示例:
sort -u -s -t, -k1,1
假设 OP 想要打印第一次出现的值$1,这里是 awk 单行:
$1
awk -F"," 'NR==1{print;next} !($1 in a){a[$1]=$0} END{for(i in a) print a[i]}' file