0

!sort -k 1n hits.csv -o output.csv

The above sorts the file according to the field preceding the first comma. But how do I keep the first line? (I want the first line of hits.csv to appear as first line in output.csv as well.)

ajfbiw.s
  • 401
  • 1
  • 8
  • 22
  • 2
    may be duplicated with http://stackoverflow.com/questions/14562423/is-there-a-way-to-ignore-header-lines-in-a-unix-sort – YCFlame Jan 26 '16 at 08:08

1 Answers1

0
$ pg test1.txt
keep this line
55, some stuff 1, other stuff 1
6, some stuff 2, other stuff 2
111, some stuff 3, other stuff 3
2, some stuff 4, other stuff 4
4, some stuff 5, other stuff 5
6, sdsdsdsdsdsdsds
7, ttttttttt

$ head -n 1 test1.txt >sorted.txt && tail -n +2 test1.txt | sort -k 1n >> sorted.txt

$ pg sorted.txt
keep this line
2, some stuff 4, other stuff 4
4, some stuff 5, other stuff 5
6, sdsdsdsdsdsdsds
6, some stuff 2, other stuff 2
7, ttttttttt
55, some stuff 1, other stuff 1
111, some stuff 3, other stuff 3
Rolf of Saxony
  • 21,661
  • 5
  • 39
  • 60