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

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

问题描述

我有以下格式的数据:

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"	" -k3nr file.txt
  sort: multi-character tab `\t'

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

正确的做法是什么?

这是示例数据.

推荐答案

使用 bash,这可以解决问题:

Using bash, this will do the trick:

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

注意单引号字符串前面的美元符号.你可以阅读关于它在 bash 的 ANSI-C 引用部分/em> 手册页.

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天全站免登陆