按第一行数字排序 [英] sorting numerically by first row
问题描述
我有一个将近900行的excel文件,我已将其另存为制表符分隔的.txt文件.我想按第一列中给出的数字对文本文件进行排序(它们的范围在0到2250之间).其他列都是数字和不同长度的字母,例如.
I have a file with almost 900 lines in excel that I've saved as a tab deliminated .txt file. I'd like to sort the text file by the numbers given in the first column (they range between 0 and 2250). The other columns are both numbers and letters of varying length eg.
myfile.txt:
myfile.txt:
0251 abcd 1234,24 bcde
2240 efgh 2345,98 ikgpppm
0001 lkjsi 879,09 ikol
我尝试过
sort -k1 -n myfile.txt > myfile_num.txt
但是我只是得到一个具有新名称的相同文件.我想得到:
but I just get an identical file with new name. I'd like to get:
myfile_num.txt
myfile_num.txt
0001 lkjsi 879,09 ikol
0251 abcd 1234,24 bcde
2240 efgh 2345,98 ikgpppm
我做错了什么?我猜这很简单,但是我会得到任何帮助,我将不胜感激!我只知道一些bash脚本,所以如果脚本是我能理解的非常简单的单行脚本,那将是很好的:)
What am I doing wrong? I'm guessing that it's quite simple, but I'd appreciate any help I can get! I only know a little bash scripting, so it'd be nice if the script is a very simple one-liner that I can understand :)
谢谢:)
推荐答案
使用此方法将旧的Mac OS回车符转换为换行符:
Use this to convert old Mac OS carriage return to newline:
tr '\r' '\n' < myfile.txt | sort
这篇关于按第一行数字排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!