Delete the set of lines from notepad which are between the strings "dynamics" and "end dynamics"

naveenraja16

New Member
Joined
Mar 3, 2016
Messages
10
Hello all,
I have a task to read a bunch of notepad files and in each of the file, i need to delete the set of lines which are present in between the strings "dynamics" and "end dynamics" and also delete those two strings as well.
The attached image shows the part which needs to be removed , wherever it has occurred (dynamics to end dynamics- any content can be present with these two boundaries) in that text file. `
rsQhg.jpg


I have also added sample lines from my notepad file below
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">L3.3

resizeText
1
zoomLines
0
zoomArrows
0
doLasso
1
opaqueMove
1
selectDistance
30
adjustFonts
1
doubleBuffer
1
clipping
1
nCopyAreas
0
drawTextLimit
0.5
saveObjects
1
canvasBackground
#050048007800
defaultForeground
#000000000000
layers
1
layerName
0 0
layerName
1 1
layerName
2 2
layerName
3 3
layerName
4 4
layerName
5 5
layerName
6 6
layerName
7 7
layerName
8 8
layerName
9 9
layerName
10 10
layerName
11 11
layerName
12 12
layerName
13 13
layerName
14 14
layerName
15 15
layerName
16 16
layerName
17 17
layerName
18 18
layerName
19 19
layerName
20 20
layerName
21 21
layerName
22 22
layerName
23 23
layerName
24 24
layerName
25 25
layerName
26 26
layerName
27 27
layerName
28 28
layerName
29 29
layerName
30 30
layerName
31 31
gend

N
0
P
0 0
T
-1
R
0 0
0
0 4 1 0
Name
#WVP
0 1 1
!
27e
054878
-1-1-1
0
0
0
0 0
dynamics
script
//***GblSymDetails***
;DTLS; GSA_TEXT = "CIUXX"
//***ApplReplace***
//GEMTool = 1
// = ASPECTLINK
end script
end dynamics
0 0 1920 1080 0 0
N
2
P
34.7792 181.549
T
2 21071 1 0 0
0 0
R
0 0
0
0 0 3 0
Name STAT5495
0 1 1
!
27e
a5a5a5
a5a5a5
0
0
0
2 0
0 0 0
0 0 0 0 1
4
0 12.7627
11.5724 0
192.874 0.255264
185.159 12.3798
N
4
P
221.604 181.887
T
2 21071 1 0 0
0 0
R
0 0
0
0 0 5 0
Name STAT5496
0 1 1
!
27e
7c7c7c
7c7c7c
0
0
0
2 0
dynamics
script
func ip_FillColor
() {
return FILLCOLOR;
}
func ip_LineColor
() {
return LINECOLOR;
}
func ip_TEXT
() {
return TEXT;
}
func BackColor
() {
return RGB(124,124,124);

}


func ForeColor
() {
return RGB(124,124,124);

}












// when ...
object.background = BackColor();
object.foreground = ForeColor();
end script
end dynamics
0 0 0
0 0 0 0 1
4
0 11.6149
6.04944 0
6.04944 54.445
0 72.5933
N
6
P
81.7124 181.888
T
2 21071 1 0 0
0 0
R
0 0
0
0 0 7 0
Name STAT5497
0 1 1
!
27e
616161
616161
0
0
0
2 0
dynamics
script
func ip_FillColor
() {
return FILLCOLOR;
}
func ip_LineColor
() {
return LINECOLOR;
}
func ip_TEXT
() {
return TEXT;
}
func BackColor
() {
return RGB(97,97,97);

}


func ForeColor
() {
return RGB(97,97,97);

}












// when ...
object.background = BackColor();
object.foreground = ForeColor();
end script
end dynamics
0 1 0
0 0 0 0 1
72
93.8536 5.86588</code>
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try this:
Code:
Sub a929549()
Dim i As Long
Dim x As Long
Dim y As Long
Dim rr As Long
Dim a As Long

Application.ScreenUpdating = False
rr = Range("A" & Rows.count).End(xlUp).row

a = Range("A2:A" & rr).Find("dynamics", SearchOrder:=xlByRows, LookAt:=xlWhole, _
  SearchDirection:=xlNext).row

For i = rr To a Step -1
  y = Range("A2:A" & rr).Find("end dynamics", SearchOrder:=xlByRows, LookAt:=xlWhole, _
  SearchDirection:=xlPrevious).row
  
  x = Range("A2:A" & rr).Find("dynamics", SearchOrder:=xlByRows, LookAt:=xlWhole, _
  SearchDirection:=xlPrevious).row

  Range(Cells(x, "A"), Cells(y, "A")).EntireRow.Delete
  i = x
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi,
I have made a code for reading a txt file and delete a set of lines in that file and save it in another location. Can you help me out in modifying the code for reading multiple files present in a particular folder and then do the process on all files and save it in a different folder .I have attached the code herewith.
Sub cleantext()
Dim lineOfText As String
Dim skipLines As Boolean
'Open files for writing
Open "C:\Users\INNAR1\Desktop\input_static_files\ebb_htr01h.UCBG" For Input As #1
Open "C:\Users\INNAR1\Desktop\output_static_files\ebb_htr01h.UCBG" For Output As #2


skipLine = False
Do Until EOF(1)
Line Input #1, lineOfText
If lineOfText = "dynamics" Then skipLines = True
If lineOfText = "end dynamics" Then skipLines = False
If Not skipLines And Not lineOfText = "end dynamics" Then Print #2, lineOfText
Loop
Close #1
Close #2
End Sub
Thanks in advance
 
Upvote 0

Forum statistics

Threads
1,217,018
Messages
6,134,046
Members
449,857
Latest member
caracal

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top