[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 337
  • Last Modified:

Remove a range of lines within a text file.

I have the following text file in which I want to remove a mid section of the file while creating a new one.

The starting point of the file that I want to start deleting lines is:  "<P>"           'I added a bunch of asterisks to the right of the line so you can see where it is.

I want to stop deleting lines when you find this string: "<table width="968" border="0" cellspacing="0" cellpadding="4">"   'I added a bunch of asterisks to the right of the line so you can see where it is.


<HTML><HEAD><TITLE>APLUS - Unix Change System</TITLE>

<META http-equiv=Content-Type content=text/html;CHARSET=iso-8859-1>
<META content="MSHTML 5.50.4522.1800" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0>

<!-- #BeginLibraryItem "/Library/aplusban.lbi" --><IMG height=90
src="http://mutualnet/is/aplus/img/aplusban.gif" width=782 useMap=#Aplusban
border=0><MAP name=Aplusban> <AREA shape=RECT alt="Aplus Contacts"
coords=707,73,778,89 href="http://mutualnet/is/aplus/contacts.htm"><AREA
shape=RECT alt=Search coords=648,73,705,89 href="http://search.nml.com/"><AREA
shape=RECT alt="MutualNet Home" coords=565,73,647,89
href="http://mutualnet.nml.com/"><AREA title="IS Home" shape=CIRCLE
alt="IS Home" coords=523,35,41
href="http://mutualnet.nml.com/is/index.htm"><AREA title="APLUS Home"
shape=RECT alt="APLUS Home" coords=1,1,475,72
href="http://mutualnet/is/aplus/index.htm"><AREA shape=RECT
coords=511,75,565,89 href="http://mutualnet/is/aplus/index.htm"></MAP><!-- #EndLibraryItem --><font face="Arial, Helvetica, sans-serif" size="5"><br>
Changes by Date Range</font>
<P>    ***********************************
<FORM NAME="aplusDynamicRpt" method="POST" action="/cgi-bin/aplus/bin/aplusDynamicRpt.pl"><b>Enter Date Range:</b>
<select name="frommonth">
<option value="Jan"  >Jan</option>
<option value="Feb"  >Feb</option>
<option value="Mar"  >Mar</option>
<option value="Apr"  >Apr</option>
<option value="May" SELECTED >May</option>
<option value="Jun"  >Jun</option>
<option value="Jul"  >Jul</option>
<option value="Aug"  >Aug</option>
<option value="Sep"  >Sep</option>
<option value="Oct"  >Oct</option>
<option value="Nov"  >Nov</option>
<option value="Dec"  >Dec</option>
</select>
<td width="14%">
<select name="impStatus">
<option>All</option>
<option>Backed Out</option>
<option>Cancelled</option>
<option>Implemented Successfully</option>
<option>Implemented with Problems</option>
<option>Not Selected</option>
<option>Partially Implemented</option>
<option>Pending</option>
<option>Postponed</option>
<option>Rescheduled</option>
</select>
</td>
</tr>
</table>
<input type="submit" name="Submit" value="Create Report">
<br>
<hr>
<font size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>*Click on header
to sort by that column</b></font><br>
<table width="968" border="0" cellspacing="0" cellpadding="4">   ***********************************
<tr bgcolor="#666666" bordercolor="#666666" align="left" valign="middle">
<td width="9%"><a href="javascript:document.aplusDynamicRpt.sortfield.value = 'chg_impl_mail_txt';document.aplusDynamicRpt.submit();"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Implementer</font></a></td>
<tr bordercolor="#666666" align="left" valign="middle" bgcolor="#CCCCCC">
<td colspan="13" width="100%"><font face="Arial, Helvetica, sans-serif" size="1">&nbsp;Client Action:
CO Action: Ignore any messages that may come out.

Service Center Action: Ignore any messages that may come out.

</font></td>
</tr>
<tr><td colspan="10">Total: 49</td></tr></table>
<br>
<p> <br>
</FORM>
<!-- #BeginLibraryItem "/Library/Owner.lbi" -->
<hr>
<div align=center><i><font size=2>| <a
href="http://search.nml.com/?browse-category=MutualNet&view-template=normal&view-hits=&ui=bw">Search</a>
| <a href="http://mutualnet/is/aplus/contacts.htm">Contacts</a> |</font></i>
</div><script language=JavaScript>
document.writeln("Last Updated: " + document.lastModified)
</script>
</i><!-- #EndLibraryItem -->
</BODY></HTML>

The new file would look like this:

<HTML><HEAD><TITLE>APLUS - Unix Change System</TITLE>

<META http-equiv=Content-Type content=text/html;CHARSET=iso-8859-1>
<META content="MSHTML 5.50.4522.1800" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0>

<!-- #BeginLibraryItem "/Library/aplusban.lbi" --><IMG height=90
src="http://mutualnet/is/aplus/img/aplusban.gif" width=782 useMap=#Aplusban
border=0><MAP name=Aplusban> <AREA shape=RECT alt="Aplus Contacts"
coords=707,73,778,89 href="http://mutualnet/is/aplus/contacts.htm"><AREA
shape=RECT alt=Search coords=648,73,705,89 href="http://search.nml.com/"><AREA
shape=RECT alt="MutualNet Home" coords=565,73,647,89
href="http://mutualnet.nml.com/"><AREA title="IS Home" shape=CIRCLE
alt="IS Home" coords=523,35,41
href="http://mutualnet.nml.com/is/index.htm"><AREA title="APLUS Home"
shape=RECT alt="APLUS Home" coords=1,1,475,72
href="http://mutualnet/is/aplus/index.htm"><AREA shape=RECT
coords=511,75,565,89 href="http://mutualnet/is/aplus/index.htm"></MAP><!-- #EndLibraryItem --><font face="Arial, Helvetica, sans-serif" size="5"><br>
Changes by Date Range</font>
<table width="968" border="0" cellspacing="0" cellpadding="4">  
<tr bgcolor="#666666" bordercolor="#666666" align="left" valign="middle">
<td width="9%"><a href="javascript:document.aplusDynamicRpt.sortfield.value = 'chg_impl_mail_txt';document.aplusDynamicRpt.submit();"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Implementer</font></a></td>
<tr bordercolor="#666666" align="left" valign="middle" bgcolor="#CCCCCC">
<td colspan="13" width="100%"><font face="Arial, Helvetica, sans-serif" size="1">&nbsp;Client Action:
CO Action: Ignore any messages that may come out.

Service Center Action: Ignore any messages that may come out.

</font></td>
</tr>
<tr><td colspan="10">Total: 49</td></tr></table>
<br>
<p> <br>
</FORM>
<!-- #BeginLibraryItem "/Library/Owner.lbi" -->
<hr>
<div align=center><i><font size=2>| <a
href="http://search.nml.com/?browse-category=MutualNet&view-template=normal&view-hits=&ui=bw">Search</a>
| <a href="http://mutualnet/is/aplus/contacts.htm">Contacts</a> |</font></i>
</div><script language=JavaScript>
document.writeln("Last Updated: " + document.lastModified)
</script>
</i><!-- #EndLibraryItem -->
</BODY></HTML>


Thanks
0
Richard Kreidl
Asked:
Richard Kreidl
  • 2
  • 2
1 Solution
 
arif_eqbalCommented:
Hi rkckjk
that can be done but just a few questions
Whenever there's a <P> I start removing text till I get
<table width="968" border="0" cellspacing="0" cellpadding="4">  
Also since it appears to be an HTML what if the width of table tag is not exactly 968 or the cell padding is not exactly 4
I mean do you want to match the full
<table width="968" border="0" cellspacing="0" cellpadding="4">  

or just "<table" would do to mark the end of deletion text ???

0
 
Richard KreidlSoftware DeveloperAuthor Commented:
Yes, when you find the "<P>" start removing lines of text until you find "<table".
0
 
arif_eqbalCommented:
ok check this one out
(change the Input and output file names to that of yours)


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim objReader As New StreamReader("c:\test.txt")
        Dim strFile As String
        Dim strRes As String
        strFile = objReader.ReadToEnd()
        objReader.Close()

        strRes = strFile.Substring(0, strFile.ToLower.IndexOf("<p>"))
        'In case you want to use full <table width ....
        'strRes &= strFile.Substring(strFile.ToLower.IndexOf("<table width=""968"" border=""0"" cellspacing=""0"" cellpadding=""4"">"))
        'In case just matching a <table would do
        strRes &= strFile.Substring(strFile.ToLower.IndexOf("<table "))

        Dim objWriter As New StreamWriter("c:\Test1.txt")
        objWriter.Write(strRes)
        objWriter.Close()
        MsgBox("done")
    End Sub
0
 
Richard KreidlSoftware DeveloperAuthor Commented:
Thanks, it works great
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now