BEGIN {} function getTag() { tag = gensub(/^ *<([a-zA-Z]+).*/,"\\1","g",$0) t = $0 # may not be on the same line - read as many as needed while ((index(t,"") == 0) && (match(t,"/> *$") == 0)) { if (getline > 0) t = t "\n" $0; else break; } #t = gensub("^ *<" tag "[^>]*>","","g",t) #t = gensub("","","g",t) return t } # scan the file # ---------------------------------------------------------------------- (FNR == 1) { part = 0 } /^ +(.*)<\/programVersion>/ { programVersion = gensub(/(.*)(.*)(<\/programVersion>.*)/,"\\2","g") if (substr(programVersion,1,2) != "2.") { print "FATAL: only scores created with MuseScore version 2.x are supported: " FILENAME > "/dev/stderr" exit } } /^ */ { Part = 1 } /^ */ { StaffId = gensub(/^[^"]+"([0-9]+)".*$/,"\\1","g",$0) } /^ *[0-9]+<\/show>/ && (Part == 1) { # remove the tag := set the visibility to yes getTag() next } /^ */ && (Part == 1) { Instrument = 1 } /^ */ && (Instrument == 1) { Channel = 1 } /^ */ && (Channel == 1) { # remove the tag := populate in the second pass getTag() next } /^ *[0-9]<\/mute>/ && (Channel == 1) { # remove the tag := populate in the second pass getTag() next } /^ *[0-9]<\/solo>/ && (Channel == 1) { # remove the tag := populate in the second pass getTag() next } /^ *<\/Channel>/ && (Instrument == 1) { Channel = 0 } /^ *<\/Instrument>/ && (Part == 1) { Instrument = 0 Channel = 0 } /^ *<\/Part>/ { Part = 0 } { print } END {}