linux - 对制表符分隔的文件进行排序

我有一个格式如下的数据:

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

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

$ 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'

正确的做法是什么?

这里是 sample data .

最佳答案

使用 bash 就可以了:

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

注意单引号字符串前面的美元符号。你可以阅读关于 它在 ANSI-C Quoting sections of the bash man page .

https://stackoverflow.com/questions/1037365/

相关文章:

python - 如何从生成器中只选择一项?

linux - ld 找不到现有的库

python - 在 Python 中,如何拆分字符串并保留分隔符?

c - 如何将文件指针 ( FILE* fp ) 转换为文件描述符 (int fd)?

python - 类型错误 : method() takes 1 positional argume

linux - 如何将stderr和stdout重定向到脚本同一行中的不同文件?

python - 为什么 Pycharm 的检查员提示 "d = {}"?

linux - Linux中的缓冲区和高速缓存有什么区别?

python - 如何重命名 conda 环境?

linux - 查找不属于特定用户的文件