Is there a way to ignore header lines in a UNIX sort?

后端 未结 12 2196
余生分开走
余生分开走 2020-11-28 21:02

I have a fixed-width-field file which I\'m trying to sort using the UNIX (Cygwin, in my case) sort utility.

The problem is there is a two-line header at the top of t

12条回答
  •  独厮守ぢ
    2020-11-28 21:39

    It only takes 2 lines of code...

    head -1 test.txt > a.tmp; 
    tail -n+2 test.txt | sort -n >> a.tmp;
    

    For a numeric data, -n is required. For alpha sort, the -n is not required.

    Example file:
    $ cat test.txt

    header
    8
    5
    100
    1
    -1

    Result:
    $ cat a.tmp

    header
    -1
    1
    5
    8
    100

提交回复
热议问题