grep + awk solution:
grep -Eo '<[^<>]+>' input.xml | awk '{ gsub(/[<>]/,""); printf "%-3s - %s\n", NR, $0 }' The output:
1 - note 2 - to 3 - /to 4 - from 5 - /from 6 - heading 7 - /heading 8 - body 9 - /body 10 - /note Or with single GNU awk command:
awk -v FPAT='</?[^<>]+>' '{ for(i=1;i<=NF;i++) printf "%-3s - %s\n", ++c, $i }' input.xml