unix - 文件中的列数 [英] unix - count of columns in file
本文介绍了unix - 文件中的列数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定一个包含这样数据的文件(即stores.dat文件)
Given a file with data like this (i.e. stores.dat file)
sid|storeNo|latitude|longitude
2|1|-28.03720000|153.42921670
9|2|-33.85090000|151.03274200
输出列名数量的命令是什么?
What would be a command to output the number of column names?
即在上面的例子中,它将是 4.(管道字符数 + 第一行中的 1 个)
i.e. In the example above it would be 4. (number of pipe characters + 1 in the first line)
我在想:
awk '{ FS = "|" } ; { print NF}' stores.dat
但它返回所有行而不是第一行,对于第一行,它返回 1 而不是 4
but it returns all lines instead of just the first and for the first line it returns 1 instead of 4
推荐答案
awk -F'|' '{print NF; exit}' stores.dat
在第一行后立即退出.
这篇关于unix - 文件中的列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文