SUMMARY: Removing lines after getting perticular text

From: VYAS RASHMIKANT /IBANK/CRP <vyasr_at_icici.com>
Date: Mon Oct 08 2001 - 08:36:14 EDT
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C14FF5.D175E1B0
Content-Type: text/plain;
	charset="iso-8859-1"

Thanx to those who replied so fast, all the answer were good 
Mentioning some of the good answers .......
First one is really good..........Answer are mentioned at the end
origianl question
Dear Gurus........ 
I need help on {awk ,sed, grep , egrep} 
I want single line command or small script which 
can do following thing........ I want to grep for 
perticular text i.e big file which contains a lot of text as below 
For e.g. my file is text1.txt which contains following lines 
I want help on sun pls help me 
aaaaaabbbbbbbbbcccccccc 
bbbbbbbccccccccccddddddddd 
ccccccccddddddddddeeeeeeeee 
ddddddddddeeeeeeeeeeffffffffffffff 
eeeeeeeeeffffffffffffffffgggggggggg 
fffffffffffffffffgggggggggggggggghhhhhhhhh 
gggggggghhhhhhhhhhhhhhhhiiiiiiiiiiiii 
hhhhhhhhhhhhhiiiiiiiiiiiiiiiiiikkkkkkkkkkk 
Now I want to grep for all occurances of text "I want help on * pls help me"

and then I want that this line and 5 lines below it( which is not fixed
format of text) will be ommited and rest 
of the data I should be able to take in some other file. 
that is my new file for e.g. text2.txt should contain only 
fffffffffffffffffgggggggggggggggghhhhhhhhh 
gggggggghhhhhhhhhhhhhhhhiiiiiiiiiiiii 
hhhhhhhhhhhhhiiiiiiiiiiiiiiiiiikkkkkkkkkkk 
Thanx=trillion


Carsten B. Knudsen [case139@mail.com]

sed '/your-search-pattern/{N;N;N;N;N;d;}'
===============================================
Andy Bach [root@wiwb.uscourts.gov]
#!/usr/bin/perl 
my $found_it = 0;
while (<>) {
  if ( /I want help on (.+) pls help me/ ) {
    $found_it ++;
    my $res = <> for 1 .. 5;
  }
  print if $found_it;
}
====================================================
Glass, David (UDB) [GlassD@bp.com]
awk '{ 
if($0="teststring")s=0 
if(++s>5)print $0 
}' input_file > output_file
================================================
Dan Lowe [dan@tangledhelix.com]
-- 


"This e-mail message may contain confidential, proprietary or legally 
privileged information. It should not be used by anyone who is not the 
original intended recipient. If you have erroneously received this message, 
please delete it immediately and notify the sender. The recipient acknowledges 
that ICICI or its subsidiaries and associated companies (including ICICI Bank)
"ICICI Group", are unable to exercise control or ensure or guarantee the 
integrity of/over the contents of the information contained in e-mail 
transmissions and further acknowledges that any views expressed in this 
message are those of the individual sender and no binding nature of the 
message shall be implied or assumed unless the sender does so expressly with 
due authority of ICICI Group. Before opening any attachments please check them 
for viruses and defects." 


------_=_NextPart_001_01C14FF5.D175E1B0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; charset=3Diso-8859-=
1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version 5.5.2653.12">
<TITLE>SUMMARY: Removing lines after getting perticular text</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2 FACE=3D"Courier New">Thanx to those who replied so fast, =
all the answer were good </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">Mentioning some of the good answers=
 .......</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">First one is really good..........A=
nswer are mentioned at the end</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">origianl question</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">Dear Gurus........</FONT><FONT FACE=3D"Ti=
mes New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">I need help on {awk ,sed, grep , egrep}</=
FONT><FONT FACE=3D"Times New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">I want single line command or small scrip=
t which</FONT><FONT FACE=3D"Times New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">can do following thing........ I want to =
grep for</FONT><FONT FACE=3D"Times New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">perticular text i.e big file which contai=
ns a lot of text as below</FONT><FONT FACE=3D"Times New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">For e.g. my file is text1.txt which conta=
ins following lines</FONT><FONT FACE=3D"Times New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">I want help on sun pls help me</FONT><FON=
T FACE=3D"Times New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">aaaaaabbbbbbbbbcccccccc</FONT><FONT FACE=
=3D"Times New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">bbbbbbbccccccccccddddddddd</FONT><FONT FA=
CE=3D"Times New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">ccccccccddddddddddeeeeeeeee</FONT><FONT F=
ACE=3D"Times New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">ddddddddddeeeeeeeeeeffffffffffffff</FONT>=
<FONT FACE=3D"Times New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">eeeeeeeeeffffffffffffffffgggggggggg</FONT=
><FONT FACE=3D"Times New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">fffffffffffffffffgggggggggggggggghhhhhhhh=
h</FONT><FONT FACE=3D"Times New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">gggggggghhhhhhhhhhhhhhhhiiiiiiiiiiiii</FO=
NT><FONT FACE=3D"Times New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">hhhhhhhhhhhhhiiiiiiiiiiiiiiiiiikkkkkkkkkk=
k</FONT><FONT FACE=3D"Times New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">Now I want to grep for all occurances of =
text &quot;<B>I want help on * pls help me</B>&quot;</FONT><FONT FACE=3D"Ti=
mes New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">and then I want that</FONT><B> <FONT SIZE=
=3D2 FACE=3D"Arial">this line and 5 lines</FONT></B><FONT SIZE=3D2 FACE=3D"=
Arial"> below it( which is not fixed format of text) will be ommited and re=
st</FONT><FONT FACE=3D"Times New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">of the data I should be able to take in s=
ome other file.</FONT><FONT FACE=3D"Times New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">that is my new file for e.g. text2.txt sh=
ould contain only</FONT><FONT FACE=3D"Times New Roman"> </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">fffffffffffffffffgggggggggggggggghhhhhhhh=
h </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">gggggggghhhhhhhhhhhhhhhhiiiiiiiiiiiii </F=
ONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">hhhhhhhhhhhhhiiiiiiiiiiiiiiiiiikkkkkkkkkk=
k </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">Thanx=3Dtrillion</FONT>
</P>
<BR>

<P><FONT SIZE=3D2 FACE=3D"Courier New">Carsten B. Knudsen [case139@mail.com=
]</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Courier New">sed '/your-search-pattern/{N;N;N;N;N=
;d;}'</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">Andy Bach [root@wiwb.uscourts.gov]<=
/FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">#!/usr/bin/perl </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">my $found_it =3D 0;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">while (&lt;&gt;) {</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp; if ( /I want help on (.+) pl=
s help me/ ) {</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp;&nbsp;&nbsp; $found_it ++;</F=
ONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp;&nbsp;&nbsp; my $res =3D &lt;=
&gt; for 1 .. 5;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp; }</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&nbsp; print if $found_it;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">}</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 FACE=3D"Arial">Glass, David (UDB) [Gla=
ssD@bp.com]</FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 FACE=3D"Arial">awk '{</FONT><FONT FACE=
=3D"Times New Roman"> </FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 FACE=3D"Arial">if($0=3D&quot;teststrin=
g&quot;)s=3D0</FONT><FONT FACE=3D"Times New Roman"> </FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 FACE=3D"Arial">if(++s&gt;5)print $0</F=
ONT><FONT FACE=3D"Times New Roman"> </FONT>
<BR><FONT COLOR=3D"#0000FF" SIZE=3D2 FACE=3D"Arial">}' input_file &gt; outp=
ut_file</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">Dan Lowe [dan@tangledhelix.com]</FONT>
</P>

<P>
<FONT FACE=3D"Zurich BT" SIZE=3D1 COLOR=3D"#0000ff"><P>"This e-mail message=
 may contain confidential, proprietary or legally privileged information. I=
t should not be used by anyone who is not the original intended recipient. =
If you have erroneously received this message, please delete it immediately=
 and notify the sender. The recipient acknowledges that ICICI or its subsid=
iaries and associated companies (including ICICI Bank) "ICICI Group", are u=
nable to exercise control or ensure or guarantee the integrity of/over the =
contents of the information contained in e-mail transmissions and further a=
cknowledges that any views expressed in this message are those of the indiv=
idual sender and no binding nature of the message shall be implied or assum=
ed unless the sender does so expressly with due authority of ICICI Group. B=
efore opening any attachments please check them for viruses and defects."</=
P>
</FONT>

</BODY>
</HTML>
------_=_NextPart_001_01C14FF5.D175E1B0--
Received on Mon Oct 8 13:36:14 2001

This archive was generated by hypermail 2.1.8 : Wed Mar 23 2016 - 16:32:33 EDT