CUT command - cutting characters from end of string

Hello,

I need to delete the final few characters from a parameter leaving just the first few. However, the characters which need to remain will not always be a string of the same length.

For instance, the parameter will be passed as BN_HSBC_NTRS/hub_mth_ifce.sf. I only need the bit before the slash - BN_HSBC_NTRS. However, this could also be passed as BN_HUB_NTRS/hub_mth_ifce.sf - slightly shorter. Is there a way of removing the /hub_mth_ifce.sf part and storing it as an additional parameter?

Thanks,

John.

awk -F/ ' {print $1}' filename > outputfile

Look at the "dirname" and "basename" commands, they should suit you.

Another possibility would be to use the "${var%%/*}" shell expansion:

myvar="abcde/1234"
print - ${myvar%%/*}           # will produce "abcde"

If your variable contains more than one "/" use the single or the double percent-sign depending on what you want to get:

myvar="abcde/1234/xyz"
print - ${myvar%%/*}           # will produce "abcde"
print - ${myvar%/*}            # will produce "abcde/1234"

bakunin