击:首先4列排序csv文件 [英] Bash: sort csv file by first 4 columns

查看:61
本文介绍了击:首先4列排序csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有被分隔的字段CSV文件;。有8个领域,我想由第一4列,我的数据进行排序中(由第1列,那么列2等第一类)

I have a csv file with fields delimited by ";". There are 8 fields, and I want to sort my data by the first 4 columns, in increasing order (first sort by column 1, then column 2, etc)

我怎样才能从在Linux命令行做到这一点?

How I can do this from a command line in linux?

我试着用开放式办公,但只让我选择3列。

I tried with open office, but it only lets me select 3 columns.

编辑:关于这一点我想我的数据进行排序领域中,三字段中包含数字值的字符串,只有一个字符串。我怎样才能与排序指定此命令?

among the fields on which I want to sort my data, three fields contain strings with numerical values, one only strings. How can I specify this with the sort command?

推荐答案

尝试:

sort -t\; -k 1,1n -k 2,2n -k 3,3n -k 4,4n test.txt

例如:

1;2;100;4
1;2;3;4
10;1;2;3
9;1;2;3

> sort -t\; -k 1,1n -k 2,2n -k 3,3n -k 4,4n temp3
1;2;3;4
1;2;100;4
9;1;2;3
10;1;2;3

这篇关于击:首先4列排序csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆