![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to get lines started with matched strings using sed or grep for loop? | AMBER | Shell Programming and Scripting | 8 | 07-13-2009 06:26 AM |
| Grep and delete lines except the lines with strings | vj8436 | Shell Programming and Scripting | 14 | 04-17-2009 12:25 PM |
| To grep 10 lines after a string in a txt file. | suman82 | Shell Programming and Scripting | 6 | 12-13-2008 01:08 AM |
| grep string & a few lines after | ashterix | Shell Programming and Scripting | 7 | 12-07-2008 09:20 AM |
| grep string & next n lines | ashterix | Shell Programming and Scripting | 8 | 11-21-2005 11:38 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
grep a string in the lines between 2 strings of a file
Hi , Please help me with the following problem: I have an xml file with the following lines Code:
<cisco:name>
<cisco:mdNm>Cisco Device 7500 A Series</cisco:mdNm>
<cisco:meNm>10.1.100.19</cisco:meNm>
<cisco:ehNm>/shelf=1</cisco:ehNm>
<cisco:subname>
<cisco:sptp>Cisco PortA Series</cisco:sptp>
<cisco:aliasNameList xsi:nil="true"/>
<cisco:owner xsi:nil="true"/>
<cisco:subportname>
<cisco:cpt>Cisco SubPort B Series</cisco:cpt>
<cisco:aliasNamesubList xsi:nil="true"/>
<cisco:userLabel xsi:nil="true"/>
</cisco:subportname>
</cisco:subname>
<cisco:subname>
<cisco:sptp>Cisco PortAB Series</cisco:sptp>
<cisco:aliasNameList xsi:nil="true"/>
<cisco:owner xsi:nil="true"/>
<cisco:subportname>
<cisco:cpt>Cisco SubPort AB Series</cisco:cpt>
<cisco:aliasNamesubList xsi:nil="true"/>
<cisco:userLabel xsi:nil="true"/>
</cisco:subportname>
</cisco:subname>
</cisco:name>
<cisco:name>
<cisco:mdNm>Cisco Device 7500B Series</cisco:mdNm>
<cisco:meNm>10.1.100.20</cisco:meNm>
<cisco:ehNm>/shelf=2</cisco:ehNm>
<cisco:subname>
<cisco:sptp>Cisco Port B Series</cisco:sptp>
<cisco:aliasNameList xsi:nil="true"/>
<cisco:owner xsi:nil="true"/>
<cisco:subportname>
<cisco:cpt>Cisco SubPort B Series</cisco:cpt>
<cisco:aliasNamesubList xsi:nil="true"/>
<cisco:userLabel xsi:nil="true"/>
</cisco:subportname>
</cisco:subname>
</cisco:name>
In My code it will first check the two strings <cisco:name> and </cisco:name> and after that it will grep the count of <cisco:cpt>. and so on continue till the end of file Code:
#!/bin/sh
sed '/<\/cisco:name>/{G;}' test.xml >temp
nawk 'BEGIN{RS=""}
{
grep -c '<cisco:cpt>' print
}' temp
rm temp
this code is not giving the the op as in first<cisco:name> and </cisco:name> loop it should give 2 then for next it would 1 plz help |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|