Solved

Parse file and delete any record that isn't a number as the first character..

Posted on 2006-11-29
2
180 Views
Last Modified: 2010-04-23
I have the text file below that I need to parse out any records that don't start with a numeric character.

* PURPOSE OTHER THAN COMPANY       *   * DIAL 222-7772 - THT/DB           *
* BUSINESS.                        *   * DIAL 222-7777 - CCC              *
************************************   ************************************
................................................................................
T - TECH SUPPORT  C - CONTRACT PROGRAMMER  * - OUTSIDE IS


USER     PROGRAMMER                 LONG    AREA TELEPHONE LOCATION
 CD TECH    NAME                  DISTANCE  CODE  NUMBER
................................................................................
1069   AARON SCOTT              762-4267 (814)
2366   ABIG JOHN                284-569 (862)
2664   ABOUDI MARY              535-3033 (814)
3941   ALGEE SHEREE             241-6665 (514)-->CELL
0237   ALT JAMES                425-6947 (814)
1843   AMBY DON                 821-3955 (862) PGR/222-2016 C/303-7435

F DAHL PROBLEMS
AMERINET PROBLEMS
AMERINET/MORRETIN  1-660-653-8008   GARY MORRETIN
AMERITECH/MULLINS  1-862-892-4432 STEVE MULLINS8
1137    AMISTAPUR GOPI          462-8507 (814)
2850   AMOD RAJA                736-8541 (814) 814-236-8523

The new file would look like this:

1069   AARON SCOTT              762-4267 (814)
2366   ABIG JOHN                284-569 (862)
2664   ABOUDI MARY              535-3033 (814)
3941   ALGEE SHEREE             241-6665 (514)-->CELL
0237   ALT JAMES                425-6947 (814)
1843   AMBY DON                 821-3955 (862) PGR/222-2016 C/303-7435
1137    AMISTAPUR GOPI          462-8507 (814)
2850   AMOD RAJA                736-8541 (814) 814-236-8523


thanks
0
Comment
Question by:rkckjk
  • 2
2 Comments
 
LVL 16

Expert Comment

by:Hillwaaa
ID: 18042500
Hi rkckjk,

Try this:

        Dim path As String = "C:\temp\somefile.txt"
        Dim pathOut As String = "C:\temp\somefileNEW.txt"

        Dim fs As IO.StreamReader
        Dim fsOut As IO.StreamWriter
        Dim str As String

        fs = New IO.StreamReader(IO.File.OpenRead(path))
        fsOut = New IO.StreamWriter(IO.File.OpenWrite(pathOut))
        While Not (fs.EndOfStream)
            str = fs.ReadLine
            If (str.StartsWith("1") Or str.StartsWith("2") Or str.StartsWith("3") Or str.StartsWith("4") Or str.StartsWith("5") Or str.StartsWith("6") Or str.StartsWith("7") Or str.StartsWith("8") Or str.StartsWith("9") Or str.StartsWith("0")) Then
                fsOut.WriteLine(str)
            End If
        End While

        fs.Close()
        fsOut.Close()

Cheers,
Hillwaaa
0
 
LVL 16

Accepted Solution

by:
Hillwaaa earned 500 total points
ID: 18042508
rkckjk,

If you need the new file to have the same name as the original, then just delete the original and rename the new as follows (after you have closed fs and fsout):

        IO.File.Delete(path)
        IO.File.Copy(pathOut, path)
        IO.File.Delete(pathOut)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now