# Insert lyrics verse before lineNo (in a MuseScore 2 .mscx file) # gawk -f #InsertLine.awk < score.mcsx # gawk -v lineNo=1 -f #InsertLine.awk < score.mcsx BEGIN { lyrics = 0 # verses are numbered 0--(n-1) if (--lineNo < 0) { lineNo = 0 } no = 0 noString = "" } # ---------------------------------------------------------------------------------------- /^ +/ { lyrics = 1 no = 0 noString = "" } /^ +[0-9]+<\/no>/ { if (lyrics > 0) { noString = $0 no = gensub(/.*(.*)<\/no>/,"\\1","g",noString) next } } /^ +<\/Lyrics>/ { if (no >= lineNo) { ++no } print "" no "" lyrics = 0 } { print $0 } # Output ------------------------------------------------------------------------------------------ END {}