Archive for 25th March 2011

Using “cut” to remove extra data.

At work we have to use Windows … so I’m stuck using mirc, and sometimes when pasting code back and forth, we want to quickly remove the extra data from the front when cutting text/data from the mirc window. It usually has a timestamp and name that need to be removed.
This does the trick quickly. You have to love the simplicity of shell commands. The “cut” command has some nice options that rarely get used, one is to list everything from field X on.. in this example start at the third field and list the rest is shown by “-f 3-”.
#!/usr/bin/bash
# stripmirc – strips fields from mirc copy/paste
# crouse

export TERM=xtermc
timestamp=`date +%T`
tempfile=”/tmp/mirc.$timestamp.tempfile”
touch ${tempfile}

# TRAP for the cleanup routine in case bad stuff happens.
trap cleanup 1 2 3 6
# Function for deleting files not needed.
cleanup ()
{
rm ${tempfile}
}

echo “Type CTRL D to end”
cat > ${tempfile}
echo “”;echo “”;echo “”;
cat ${tempfile} | cut -d” ” -f 3-
rm ${tempfile}
exit 0