pattern extract

Hi

I have a pattern like :
SYSTEM_NAME-232-S7-200810060949.LOG

Here I need to extract system name and the timestamp and also the numeric number after "-S" i.e 7 here .

I am not very sure of whether I should use sed / awk for this ?:confused:

Thanks,
Priya.

I am not good at doing cut cmd .
Tried some of the below cmds !

$ echo SYSTEM_NAME-232-S7-200810060949.LOG | cut -f3 -d"-"
S7
( i need 7 only)
$echo SYSTEM_NAME-232-S7-200810060949.LOG | cut -f1 -d"-"
SYSTEM_NAME
( i need SYSTEM_NAME-232 )

I am actually very confused .....Trying out variations but not that successful until now :frowning:

Use parameter expansion:

var=SYSTEM_NAME-232-S7-200810060949.LOG
echo ${var:17:1}
echo ${var%-*-*}
> echo SYSTEM_NAME-232-S7-200810060949.LOG | cut -d"-" -f3 | cut -c2-
7
> echo SYSTEM_NAME-232-S7-200810060949.LOG | cut -c1-15
SYSTEM_NAME-232
> echo SYSTEM_NAME-232-S7-200810060949.LOG | cut -d"-" -f1-2         
SYSTEM_NAME-232

Thanks for the reply ...

What abt the timestamp ? I did the below

$echo SYSTEM_NAME-232-S7-200810060949.LOG | cut -d"-" -f 4|cut -d"." -f1

200810060949

but wondering that if this will be applicable if there is one less "-" in the string !?
Then it might give entirely different output!

sed 's/.*\(20[0-9]\{10\}\).*/\1/'