2

I'm using csvfix to sort a CSV file based on an integer (counter) value in the second column. However it seems that csvfix puts double quotes around all fields in the file, turning them to strings, before it performs the sort. The result is that the rows are sorted by the string value, such that "1000" comes before "2".

There is a command-line option -smq that is supposed to apply "smart quoting" but that's not helping me. If I use the command csvfix echo -smq file.csv, the output has no quotes around numerical fields, but when I pipe that into csvfix sort -f 2 file.csv, the file is written without quotes but still sorted in "string order". It makes no difference whether I include the -smq flag in the sort command or not.

Additionally I would like csvfix to ignore the first row of string headers. Csvfix issue tracking claims this is already implemented but I can only find the -ifn flag that seems to cut the header row out entirely.

These seem pretty basic pieces of functionality for this tool, so I'm probably missing something very simple. Hoping someone on here has used csvfix and figured out.

4

1 に答える 1

1

csvfixのオンライン ドキュメントによると、 sort にはN数値ソートのオプションがあります。

csvfix sort -f 2:N file.csv 

そうは言っても、CSVはテキスト操作に特に適した形式ではありません。可能であれば、タブ区切りやパイプ区切りなどの DSV (区切り記号で区切られた値) を選択することをお勧めします。これsortにより、必要な照合方法を使用して、フィールドで並べ替える十分な機能を備えた に出力を単純にパイプできます。

于 2012-05-27T17:22:05.430 に答える