计算一个管道分隔文件中的列数 [英] Count number of column in a pipe delimited file
本文介绍了计算一个管道分隔文件中的列数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个管 |
分隔的文件。
文件:
106232145 |医保|医疗保险,医疗| 789
我想计数在每个行中的字段的数目。我想下面的code
code:
的awk -F| {打印NF-1}
这将返回我结果为5,而不是4.这是因为AWK以医疗保险|医疗作为两个不同的领域,而不是一个字段的
解决方案
的awk -F \\ | '{print NF将}
给出正确的结果。
I have a pipe |
delimited file.
File:
106232145|"medicare"|"medicare,medicaid"|789
I would like to count the number of fields in each line. I tried the below code
Code:
awk -F '|' '{print NF-1}'
This returns me the result as 5 instead of 4. This is because the awk takes "medicare|medicaid" as two different fields instead of one field
解决方案
awk -F\| '{print NF}'
gives correct result.
这篇关于计算一个管道分隔文件中的列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文