You don't say what platform you are using, but I'm going to guess some flavour of Linux for EMC.
The following command will do what you are after, (fileIn and fileOut will need replacing with real file names)
sed -e 's/^[mM]101/M8/' -e 's/^[mM]103/M9/' -e 's/^[mM]104.*$//' -e 's/^[mM]105.*$//' -e '/^$/ d' fileIn > fileOut
If you need to convert other commands just add an extra, (XXX is the command to replace, MYYY is the replacement command):
-e '/^[mM]XXX/MYYY/'
or to remove a type of command add, (XXX is the number of the command to remove):
-e '/^[mM]XXX.$//'
The final -e block removes blank lines created where m104 and m105 commands were.
Rather than having to copy and paste it repeatedly, the code below when pasted into a shell window, running bash, will create a program called convert.sh
As a final note you will have to type /path/convert.sh, being in the same directory as the program doesn't remove this criteria but you can use the shortened path ./convert.sh
cat < convert.sh
#!/bin/sh
if [ \$# -ne 2 ]; then
echo 1>&2 Usage: \$0 \ \ \$
exit 127
fi
/bin/sed -e 's/^[mM]101/M8/' -e 's/^[mM]103/M9/' -e 's/^[mM]104.*$//' -e 's/^[mM]105.*$//' -e '/^$/ d' \$1 > \$2
EOF
chmod a+x convert.sh