1

ヘッダー構文が であるマークダウン ページがあります!!!。例えば:

!!! Better Heading
This section has a sub-heading
!! Sub-Heading one

!!! Can't think of another one
umm...


!!! A Great Heading
Some text here

テキストのブロックをアルファベット順にソートしたいと思います!!!!!!

そうする方法はありますか?

4

1 に答える 1

2

これを試して :

perl -ne 's/^(?!!!!)/###/g; print;' file | sed ':a;N;$!ba;s/\n###/###/g' | sort | sed 's/###/\n/g'

最初にすべての非ヘッダー行をマークします:

perl -ne 's/^(?!!!!)/###/g; print;' file

!!! Better Heading
###This section has a sub-heading
###!! Sub-Heading one
###
!!! Can't think of another one
###umm...
###
###
!!! A Great Heading
###Some text here

次に、\nこれらの行の前に削除します。

perl -ne 's/^(?!!!!)/###/g; print;' file | sed ':a;N;$!ba;s/\n###/###/g' 

!!! Better Heading###This section has a sub-heading###!! Sub-Heading one###
!!! Can't think of another one###umm...######
!!! A Great Heading###Some text here

次に、マーカーを並べ替えて次のように置き換えます\n

perl -ne 's/^(?!!!!)/###/g; print;' file | sed ':a;N;$!ba;s/\n###/###/g' | sort | sed 's/###/\n/g'

!!! A Great Heading
Some text here
!!! Better Heading
This section has a sub-heading
!! Sub-Heading one

!!! Can't think of another one
umm...
于 2014-05-20T04:53:00.920 に答える