Ekuskowski
asked on
need to find and replace numbers within a document and increment by 1
I have a text file which is a deposition transcript ( a simple TXT file ) laid out as follows.
00000
1 jkfdkjdfjkdfdjfk
2 sdfkjsdfdjkfdjkfdfkj
3 dfkldfkldfkldfkldfkldfkl
4 kldfkdfkdfkdlfkdfldfkl
5 kfdlkdflkdfklfdklfd
6 dfjkdfjkfdjdkffjkdfdjk
7 dfkldfkldfkldfkldfkldfkl
00001
1 jkfdkjdfjkdfdjfk
2 sdfkjsdfdjkfdjkfdfkj
3 dfkldfkldfkldfkldfkldfkl
4 kldfkdfkdfkdlfkdfldfkl
5 kfdlkdflkdfklfdklfd
6 dfjkdfjkfdjdkffjkdfdjk
7 dfkldfkldfkldfkldfkldfkl
00002
1 jkfdkjdfjkdfdjfk
2 sdfkjsdfdjkfdjkfdfkj
3 dfkldfkldfkldfkldfkldfkl
4 kldfkdfkdfkdlfkdfldfkl
5 kfdlkdflkdfklfdklfd
6 dfjkdfjkfdjdkffjkdfdjk
7 dfkldfkldfkldfkldfkldfkl
The five digit numbers represent page numbers, the single digits represent line numbers. Each page actually has 25 lines per page and the page numbers actually go up to about 500.
My problem is , whoever created this file started with page 00000 and not page 00001 , so now the program that reads this file is incorrect by one page.
I want to know if anyone has any idea how I could easily fix the page numbering in this txt file. I was thinking of some kind of advanced find and replace and increment by 1 ?
Any thoughts are appreciated
00000
1 jkfdkjdfjkdfdjfk
2 sdfkjsdfdjkfdjkfdfkj
3 dfkldfkldfkldfkldfkldfkl
4 kldfkdfkdfkdlfkdfldfkl
5 kfdlkdflkdfklfdklfd
6 dfjkdfjkfdjdkffjkdfdjk
7 dfkldfkldfkldfkldfkldfkl
00001
1 jkfdkjdfjkdfdjfk
2 sdfkjsdfdjkfdjkfdfkj
3 dfkldfkldfkldfkldfkldfkl
4 kldfkdfkdfkdlfkdfldfkl
5 kfdlkdflkdfklfdklfd
6 dfjkdfjkfdjdkffjkdfdjk
7 dfkldfkldfkldfkldfkldfkl
00002
1 jkfdkjdfjkdfdjfk
2 sdfkjsdfdjkfdjkfdfkj
3 dfkldfkldfkldfkldfkldfkl
4 kldfkdfkdfkdlfkdfldfkl
5 kfdlkdflkdfklfdklfd
6 dfjkdfjkfdjdkffjkdfdjk
7 dfkldfkldfkldfkldfkldfkl
The five digit numbers represent page numbers, the single digits represent line numbers. Each page actually has 25 lines per page and the page numbers actually go up to about 500.
My problem is , whoever created this file started with page 00000 and not page 00001 , so now the program that reads this file is incorrect by one page.
I want to know if anyone has any idea how I could easily fix the page numbering in this txt file. I was thinking of some kind of advanced find and replace and increment by 1 ?
Any thoughts are appreciated
Is this definitely a text file?
Also, must the solution be code, or are you open to a non-code solution?
Also, must the solution be code, or are you open to a non-code solution?
ASKER
yes it is a text file
I would prefer a non code solution I'm not very good with code
U
I would prefer a non code solution I'm not very good with code
U
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You will have to use VBA code unless you want to do multiple Find and Replace operations
There is some get-you-started advice for VBA at the end of this article:
https://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Word/A_7236-Macro-code-to-convert-text-to-fields-in-Microsoft-Word.htm
Sub MultiReplace()
Dim i As Integer
For i = 1 To ActiveDocument.Paragraphs.Count Step 8
ActiveDocument.Paragraphs(i).Range.Text = Format((i / 8) + 1, "00000") & vbCr
Next i
End Sub
There is some get-you-started advice for VBA at the end of this article:
https://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Word/A_7236-Macro-code-to-convert-text-to-fields-in-Microsoft-Word.htm
ASKER
Code worked perfectly. Thank you
Welcome, glad that helped, thanks for the feedback.
~bp
~bp
Open a temp file for Output
Open the current file file for Input
Read and ignore the first line
Write 00001 to the temp file using a counter that starts at 00001
Read and write the next 25 lines to the temp file
Read and ignore the next line
Increment the counter by one and write 00002 to the temp file
etcetrta until the current file is at EOF
close both files
Kill the current file
rename the temp file with the current file name