Altering a variable

Can I take an argument input, lets say it's, hg0000_xy1_v2, in the script it becomes f ... then hack off the end of the filename to change the variable to hg0000 only.

I tried using sed but can't figure it out.

f="$f" | sed 's/_fg[0-9]_v[0-9]//'

I could change the variable label if necessary to anything other than f if that's easier. I just need to be able to work with only the first 6 characters of the filename.

Any ideas?

Thanks

Did not test, sometime like

f=hg0000_xy1_v2
f={f%%_*}     
echo ${f}

or

f=hg0000_xy1_v2
f=`echo ${f} | cut -d _ -f1`

In bash/ksh you can get 1st 6 chars of f with ${f:0:6}

$ f=hg0000_xy1_v2
$ echo ${f:0:6}
hg0000

${f:0:6} worked perfectly.

Thank you.

More general (as blackrageous suggested dollarlessly):

echo "${f%%_*}"