How to sort with multiple lines in bash?

前端 未结 3 723
太阳男子
太阳男子 2021-01-02 09:50

I am trying to sort a list of names followed by another string such as:

John Doe
AVAIL

Sara Doe
CALL

Jim Doe
AVAIL

I am trying to sort th

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-02 10:34

    Probably far from optimal, but

    sed -r ':r;/(^|\n)$/!{$!{N;br}};s/\n/\v/g' names | sort | sed 's/\v/\n/g'
    

    seems to do the job (names is the file with records). This allows records of arbitrary length, not just 2 lines.

提交回复
热议问题