如何在 Windows 中获取 CSV 文件中的可变列数?

How to get the variable number of columns in a CSV file in Windows?

作为仅执行 awk 命令的 kdb q 系统的一部分,我可以在 CSV 文件中找到要加载到 kdb 中的列数。

.helper.ux.getnumberofcolumns:{[filename]
  ncols:@[system;"awk -F, '{print NF; exit}' ",filename;()];
  :first {"I"$x} @/: ncols;}

基于 awk 的系统命令只是在做 awk -F, '{print NF; exit}' <filename>

我可以在 Windows shell batch/cmd 等中使用类似的命令来完成同样的事情吗? important 无需安装 Cygwin(公司内部无法安装)

Powershell:

Get-Content .\awk.txt | %{ $a=$_.Split(','); Write-Host "No of fields in record="$a.length; break; }

有关此内容的更多信息 here

假设csv中所有行的字段数相同,可以根据文件的第一条记录来确定文件中的字段数

{count "," vs raze "head -1 ",x}