Sign in to follow this  
Followers 0
dancer58

number text lines in file

4 posts in this topic

I have text (.csv) file I need to number. It has appr. 1000 lines and over 60% have the same name.

There is one thing in common and that is every line has COE in caps. COE is not in the same place in each line.

I need to number each line starting with 1 and incrementing by 1 for each line. I need the numbering to be at the end of COE. COE1 COE2 ect.

Does anyone have a program that I can use/modify to do this

Thanks

Harold

Share this post


Link to post
Share on other sites



Hi,untested, modify;

; filereadd.au3
#include <file.au3>
Dim $aRecords
If Not _FileReadToArray("error.log", $aRecords) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
    Exit
EndIf
For $x = 1 To UBound($aRecords)-1
    $aRecords[$x] = StringReplace($aRecords[$x], "COE", "COE" & $x)
Next
FileDelete("error.log")
_FileWriteFromArray("error.log",$aRecords,1)
Best, Randall

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi,untested, modify;

; filereadd.au3
#include <file.au3>
Dim $aRecords
If Not _FileReadToArray("error.log", $aRecords) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
    Exit
EndIf
For $x = 1 To UBound($aRecords)-1
    $aRecords[$x] = StringReplace($aRecords[$x], "COE", "COE" & $x)
Next
FileDelete("error.log")
_FileWriteFromArray("error.log",$aRecords,1)
Best, Randall
:) Thanks_____This did the job

#include <file.au3>

Dim $aRecords

If Not _FileReadToArray("d:\downloads\CorpsofEng.csv",$aRecords) Then

MsgBox(4096,"Error", " Error reading log to Array error:" & @error)

Exit

EndIf

For $x = 1 to $aRecords[0]

;Msgbox(0,'Record:' & $x, $aRecords[$x])

$aRecords[$x] = StringReplace($aRecords[$x], "COE", "COE" & $x)

Next

FileDelete("c:\Program Files\AutoIt3\au3 files\CorpsofEng.csv")

_FileWriteFromArray("d:\downloads\CorpsofEng.csv",$aRecords,1)

Thanks for the input

Edited by dancer58

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0