我试图用",“分隔来打印awk命令的输出。试图获得相同的输出使用削减。
cat File1
dot|is-big|a
dot|is-round|a
dot|is-gray|b
cat|is-big|a
hot|in-summer|a
dot|is-big|a
dot|is-round|b
dot|is-gray|a
cat|is-big|a
hot|in-summer|a已尝试指挥:
$awk 'BEGIN{FS="|"; OFS=","} {print $1,$3}' file1.csv | sort | uniq -c产出:
2 cat,a
4 dot,a
2 dot,b
2 hot,a期望产出:
2,cat,a
4,dot,a
2,dot,b
2,hot,a其他几个命令尝试了:
$cat file1.csv |cut --output-delimiter="|" -d'|' -f1,3 | sort | uniq -c发布于 2019-06-24 21:19:34
运行,后,需要将分隔符更改为uniq -c,因为它添加了第一列。
awk -F'|' '{print $1, $3}' file1.csv | sort | uniq -c | awk 'BEGIN{OFS=","} {$1=$1;print}'但是您不需要使用sort | uniq -c,如果您使用的是awk,它可以自己进行计数。
awk 'BEGIN{FS="|";OFS=","} {a[$1 OFS $3]++} END{for(k in a) print a[k], k}' file1.csvhttps://stackoverflow.com/questions/56743999
复制相似问题