Discussion:
Beginner -
v***@yahoo.com
2014-02-24 16:49:19 UTC
Permalink
Example data file 10.10.10.10.log :


primary
Factory CTS 1.9.6(2) P1
*Slot 1 CTS 1.9.6(2) P1
Slot 2 CTS 1.7.1(4864) P1
loads file information
Factory (cmterm-CTS.1-9-6-2R-K9.P1)
CTS: CTS.1-9-6-2R-K9.P1.sbn
Touch: CTSDEV.1-9-6-2R-K9.P1.SPA
Slot 1 (cmterm-CTS.1-9-6-2R-K9.P1)
CTS: CTS.1-9-6-2R-K9.P1.sbn
Touch: CTSDEV.1-9-6-2R-K9.P1.SPA-G
Slot 2
No loads file

I look for primary and * to isolate the interesting slot number.
slot=`sed '/^primary$/,/\*/!d' 10.10.10.10.log | tail -1 | sed s'/*//' | awk '{print $1" "$2}'`
slot = "Slot 1"
Now I want to get the Touch line for the associate slot number, in this case, because the asterisk indicates the interesting slot, "Slot 1"

sed -n '/\s+"$gslot"/p; /Touch:/p' 10.10.10.10.log
The response
.
Slot 1
Touch: CTSDEV.1-9-6-2R-K9.P1.SPA
Touch: CTSDEV.1-9-6-2R-K9.P1.SPA-G

My question is \
How do I get only the touch line following the Slot 1 line ?
Jim Hill
2014-02-24 21:17:37 UTC
Permalink
Using GNU sed:

sed -nr '
/^primary$/!{H;$!d;g}
// {x;1d}
s/.*\n *\*(Slot [0-9]*).*\n( *\1[^\n]*).*/\2/p
'
Post by v***@yahoo.com
primary
Factory CTS 1.9.6(2) P1
*Slot 1 CTS 1.9.6(2) P1
Slot 2 CTS 1.7.1(4864) P1
loads file information
Factory (cmterm-CTS.1-9-6-2R-K9.P1)
CTS: CTS.1-9-6-2R-K9.P1.sbn
Touch: CTSDEV.1-9-6-2R-K9.P1.SPA
Slot 1 (cmterm-CTS.1-9-6-2R-K9.P1)
CTS: CTS.1-9-6-2R-K9.P1.sbn
Touch: CTSDEV.1-9-6-2R-K9.P1.SPA-G
Slot 2
No loads file
I look for primary and * to isolate the interesting slot number.
slot=`sed '/^primary$/,/\*/!d' 10.10.10.10.log | tail -1 | sed s'/*//' |
awk '{print $1" "$2}'`
slot = "Slot 1"
Now I want to get the Touch line for the associate slot number, in this
case, because the asterisk indicates the interesting slot, "Slot 1"
sed -n '/\s+"$gslot"/p; /Touch:/p' 10.10.10.10.log
The response
.
Slot 1
Touch: CTSDEV.1-9-6-2R-K9.P1.SPA
Touch: CTSDEV.1-9-6-2R-K9.P1.SPA-G
My question is \
How do I get only the touch line following the Slot 1 line ?
satish
2014-02-24 21:23:33 UTC
Permalink
Try this after you get the slot variable.

sed "/$slot (/,/Touch" filename l grep Touch

Regards,
Satish
Post by v***@yahoo.com
primary
Factory CTS 1.9.6(2) P1
*Slot 1 CTS 1.9.6(2) P1
Slot 2 CTS 1.7.1(4864) P1
loads file information
Factory (cmterm-CTS.1-9-6-2R-K9.P1)
CTS: CTS.1-9-6-2R-K9.P1.sbn
Touch: CTSDEV.1-9-6-2R-K9.P1.SPA
Slot 1 (cmterm-CTS.1-9-6-2R-K9.P1)
CTS: CTS.1-9-6-2R-K9.P1.sbn
Touch: CTSDEV.1-9-6-2R-K9.P1.SPA-G
Slot 2
No loads file
I look for primary and * to isolate the interesting slot number.
slot=`sed '/^primary$/,/\*/!d' 10.10.10.10.log | tail -1 | sed s'/*//' |
awk '{print $1" "$2}'`
slot = "Slot 1"
Now I want to get the Touch line for the associate slot number, in this
case, because the asterisk indicates the interesting slot, "Slot 1"
sed -n '/\s+"$gslot"/p; /Touch:/p' 10.10.10.10.log
The response
.
Slot 1
Touch: CTSDEV.1-9-6-2R-K9.P1.SPA
Touch: CTSDEV.1-9-6-2R-K9.P1.SPA-G
My question is \
How do I get only the touch line following the Slot 1 line ?
Jim Hill
2014-02-24 23:00:49 UTC
Permalink
I'm sorry, my previous was very incomplete. Here's the real one:

sed -nr '
/^primary$/!{H;$!d;g}
// {x;1d}
s/.*\n *\*Slot ([0-9]*).*\n(( *)Slot \1[^\n]*\n(\3 [^\n]*\n)*).*/\2/
s/.*\n( *Touch: [^\n]*).*/\1/p
'

​The first substitution backreferences are: \1 is the slot number, \2 is
the entire slot group, \3 is the number of leading spaces before the slot
group header line, it searches for the slot group header and the following
lines with at least that much indentation.​
​

Loading...