filename.csv
我有一个包含内容的CSV 文件。
,"Range 1 (%)","Range 2 (%)"
"Color","Number Color 1","Number Color 2"
"Red","99.0","5.2"
"Orange","12.9","0.0"
"Yellow","33.9","1.2"
"Green","13.9","76.2"
"Blue","87.6","97.2"
"Purple","86.8","55.5"
我正在尝试按第二列中的值对文件进行数字排序。但是,文件的前两行是标题,我想省略它们。我的命令如下,但它输出原始文件,没有前两行,但也没有按第二列排序。
awk -F ',' '(NR>2)’ filename.csv | sort -t',' -k2 -n
感谢任何帮助:) 谢谢!
答案1
作为一个变体:
head -n 2 file.csv && tail -n +3 file.csv | sort -k 2
只需分别处理标题行和数据行即可。
如果你想将结果传递给其他东西,你可以做括号:
(head -n 2 file.csv && tail -n +3 file.csv | sort -k 2) | less