priyam
1
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 ?
Thanks,
Priya.
priyam
2
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
Use parameter expansion:
var=SYSTEM_NAME-232-S7-200810060949.LOG
echo ${var:17:1}
echo ${var%-*-*}
joeyg
4
> 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
priyam
6
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!
danmero
7
sed 's/.*\(20[0-9]\{10\}\).*/\1/'