Need help in script

Hi,

I need help.

filename comes like this

20150217-v1-PH_THOMSON_Reuters_Bangkok_Conceptual_Ready_P20_170215

and i want to extract part of the string in the filename as "

PH_THOMSON_Reuters_Bangkok_Conceptual_Ready_P

". Could you please help me to extract the string.

Ouput :

PH_THOMSON_Reuters_Bangkok_Conceptual_Ready_P

Could you please help me

Thanks in advance

This will work only for the given format.

echo "20150217-v1-PH_THOMSON_Reuters_Bangkok_Conceptual_Ready_P20_170215"|cut -d'-' -f3

I'm assuming that you are using a Bourne like shell. You could use parameter expansion.

filename=20150217-v1-PH_THOMSON_Reuters_Bangkok_Conceptual_Ready_P20_170215

filename=${filename%??_*} # remove the shortest match from the right side of the parameter

filename=${filename##*-} # remove the longest match from the left side of the parameter

echo $filename
PH_THOMSON_Reuters_Bangkok_Conceptual_Ready_P