BASH:打印以制表符分隔的文件中唯一元素的总数
我的档案BASH:打印以制表符分隔的文件中唯一元素的总数,bash,Bash,我的档案 01 01 A Value1 Value2 Value3 Something SomeMore 01 01 A Value1 Value2 Value3 Something SomeMore 01 01 A Value1 Value2 Value4 Something SomeMore 01 01 A Value1 Value2 Value5 Something SomeMore
01 01 A Value1 Value2 Value3 Something SomeMore
01 01 A Value1 Value2 Value3 Something SomeMore
01 01 A Value1 Value2 Value4 Something SomeMore
01 01 A Value1 Value2 Value5 Something SomeMore
01 01 A Value1 Value2 Value6 Something SomeMore
01 01 A Value1 Value2 Value6 Something SomeMore
...[more1000 similar lines]
那么,如何提取制表符分隔文件的第6列并打印唯一值的总数???请尝试以下内容,并让我知道这是否对您有帮助
awk '!a[$6]++{count++};END{print count}' Input_file
对制表符分隔的输入文件也使用awk'BEGIN{FS=“\t”}
解决方案2:在GNUawk中,具有数组长度
awk '{!a[$6]++} END{print length(a)}' Input_file
两种解决方案的输出如下:
awk '!a[$6]++{count++};END{print count}' Input_file
4
***********
awk '{!a[$6]++} END{print length(a)}' Input_file
4
堆栈溢出不是一种代码编写服务。欢迎使用SO,请始终尝试在post in代码标记中发布输入和输出示例。我们都在这里学习,干杯,快乐学习。@Vaibhavi Ananthakrishnan,如果您只需要第6栏的唯一值,请告诉我们您是否需要这里?cut-f 6 myFile | sort-u | wc-l
就可以了。有更好的方法,但其中一种方法快速、简单且易于理解。@diginoise,它对我来说很好,我在两种代码中都得到了4
输出,请务必让我知道它是如何对您不起作用的?