Linux command
csvsort 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Sort by column
csvsort -c [column] [data.csv]
Sort descending
csvsort -r -c [column] [data.csv]
Sort by multiple columns
csvsort -c [col1,col2] [data.csv]
Sort numerically
csvsort -c [amount] [data.csv]
Sort with no header
csvsort -H -c [1] [data.csv]
Read from stdin
cat [data.csv] | csvsort -c [name]
说明
csvsort sorts CSV files by one or more columns. Part of csvkit, it properly handles CSV quoting and data types, detecting numeric and date values for appropriate sorting. The tool maintains CSV structure during sorting, preserving headers and quoted fields correctly.
参数
- -c _columns_
- Column(s) to sort by.
- -r, --reverse
- Sort in descending order.
- -H, --no-header-row
- Input has no header.
- -d _char_
- Field delimiter.
- -q _char_
- Quote character.
- -e _encoding_
- Input encoding.
- -y _n_
- Rows to sniff for type.
FAQ
What is the csvsort command used for?
csvsort sorts CSV files by one or more columns. Part of csvkit, it properly handles CSV quoting and data types, detecting numeric and date values for appropriate sorting. The tool maintains CSV structure during sorting, preserving headers and quoted fields correctly.
How do I run a basic csvsort example?
Run `csvsort -c [column] [data.csv]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -c _columns_ do in csvsort?
Column(s) to sort by.