how to redo numbers in a log file

i have a log file

the first field(delimed by a comma) is the record number

in my file i have it auto reset to 1 each night..but on some of my logs its not doing that right so i need to do a matenance type thing and redo the line numbers...

the thing is i have multi line record numbers ie:

1
2
2
3
4
5
5
5
6
6
7
8
9
9
9
 it can be like that...
what im looking for if the second line is something other then a 1 i want it to rebuld the record numbers starting at 1. bare in mind it needs to check if its on the same number and change approprately ie:
23
23
24
25
26
26
26
27
28
28
29
would be
1
1
2
3
4
4
4
5
6
6
7

thanks for any help provided
Johnny
aka Pern
JohnnyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobertRFreemanCommented:
Just subtract the first number minus 1 (23 -1 = 22) from each number.

23 - (23 - 1) = 1
23 - (23 - 1) = 1
24 - (23 - 1) = 2
etc.
0
Fernando SotoRetiredCommented:
Hi Johnny;

This should do what you want.

Imports System.IO
Imports System.Text.RegularExpressions


        Dim filename As String = "C:\Temp\LogFile.log"
        Dim nl As String = ControlChars.CrLf
        Dim sr As New StreamReader(filename)
        Dim input() As String = Regex.Split(sr.ReadToEnd(), nl)
        sr.Close()
        Dim lineno As String = input(1).Substring(0, input(1).IndexOf(","c)).Trim()
        Dim temp As String
        Dim curNum As Integer = 1

        If lineno <> "1" Then
            input(1) = curNum.ToString() & input(1).Substring(input(1).IndexOf(","c))
            For i As Integer = 2 To input.Length - 1
                temp = input(i).Substring(0, input(i).IndexOf(","c)).Trim()
                If Not lineno = temp Then
                    lineno = temp
                    curNum += 1
                End If
                input(i) = curNum.ToString() & input(i).Substring(input(i).IndexOf(","c))
            Next
            Dim newLog As String = String.Join(nl, input)
            ' This writes to the same input file. So if you do not want that
            'change the name
            Dim sw As New StreamWriter(filename)
            sw.Write(newLog)
            sw.Close()
        End If

Fernando
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JohnnyAuthor Commented:
sorry took so long.. my computer crashed
0
Fernando SotoRetiredCommented:
Not a problem. You have a good day.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.