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

后端 未结 12 2213
余生分开走
余生分开走 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:26

    With Python:

    import sys
    HEADER_ROWS=2
    
    for _ in range(HEADER_ROWS):
        sys.stdout.write(next(sys.stdin))
    for row in sorted(sys.stdin):
        sys.stdout.write(row)
    

提交回复
热议问题