Solved

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

Posted on 2006-11-29
2
179 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

20 Experts available now in Live!

Get 1:1 Help Now