排序制表符分隔的文件 [英] Sorting a tab delimited file

查看:134
本文介绍了排序制表符分隔的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下格式的数据:

foo<tab>1.00<space>1.33<space>2.00<tab>3

现在,我尝试根据最后一个字段递减地对文件进行排序. 我尝试了以下命令,但是没有按照我们的预期排序.

Now I tried to sort the file based on the last field decreasingly. I tried the following commands but it wasn't sorted as we expected.

$ sort -k3nr file.txt  # apparently this sort by space as delimiter

$ sort -t"\t" -k3nr file.txt
  sort: multi-character tab `\\t'

$ sort -t "`/bin/echo '\t'`" -k3,3nr file.txt
  sort: multi-character tab `\\t'

什么是正确的方法?

这是样本数据.

推荐答案

使用 bash ,可以解决问题:

$ sort -t$'\t' -k3 -nr file.txt

注意单引号字符串前面的美元符号.您可以阅读有关 在 bash 手册页.

Notice the dollar sign in front of the single-quoted string. You can read about it in the ANSI-C Quoting sections of the bash man page.

这篇关于排序制表符分隔的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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