GNU sed的代码:解释
sed -n '/Mysql/{g;1!p;};h'
h # copy pattern space to hold space
/Mysql/{ # commands if the first pattern /Mysql/ is found
g # copy hold space to pattern space, in first /Mysql/ "#Database" is in hold space from the last line "h" command
1!p # print the pattern space except in line #1, "#Database" is printed
h # copy pattern space "#Database" to hold space
/Mysql/{ # commands if the second pattern /Mysql/ is found
g # copy hold space to pattern space, in second /Mysql/ "#Database" is again in hold space from last "h" command
1!p # print the pattern space except in line #1, "#Database" is printed again
h # copy pattern space "#Database" to hold space
/Mysql/{ # commands if the third pattern /Mysql/ is found
g # copy hold space to pattern space, in third /Mysql/ is "Queries" in hold space from last line "h" command
1!p # print the pattern space except in line #1, "Query" is printed now
h # copy pattern space to hold space
} end program