extract block of data delimited by parentheses

tuli1954

New Member
Joined
Apr 26, 2018
Messages
13
hello,

I have a text file with blocks of data defined by parentheses, something similar to

(
asas
dsdss
)
(
wwqee
weqqe
)

I need to extract the content between the parentheses. the problem is that sometimes the parentheses are nested.
any suggestions?

Thank you
 
MAIN_REFLECTOR_TYPE ROTATIONAL
(
FILE_NAME :
"MAIN_SUREFACE.SFC",
R_UNIT : in,
Z_UNIT : in,
N_POINTS : 1171
)

SUB_REFLECTOR_TYPE ROTATIONAL
(
FILE_NAME :
"SUB_SURFACE.SFC",
R_UNIT : in,
Z_UNIT : in,
N_POINTS : 874
)

MAIN_RIM ELLIPTICAL_RIM
(
HALF_AXIS : STRUCT(X: 19.5 in,Y: 19.5 in)
)

SUB_RIM ELLIPTICAL_RIM
(
HALF_AXIS : STRUCT(X: 3 in,Y: 3 in)
)

MAIN_REFLECTOR REFLECTOR
(
COOR_SYS : REF(ORIGIN),
SURFACE : REF(MAIN_REFLECTOR_TYPE),
RIM : REF(MAIN_RIM),
CENTRE_HOLE_RADIUS : 3 in
)

SUB_REFLECTOR REFLECTOR
(
COOR_SYS : REF(ORIGIN),
SURFACE : REF(SUB_REFLECTOR_TYPE),
RIM : REF(SUB_RIM),
CENTRE_HOLE_RADIUS : 0 in
)

D3_PLOT D3_PLOT
(
)

COOR_PLOT COOR_PLOT
(
AXIS_LENGTH : 19.5 in
)

FEED_PLOT FEED_PLOT
(
)

REFL_PLOT REFL_PLOT
(
)

PARA_PLOT PARA_PLOT
(
)

TRIANGLE_PLOT TRIANGLE_PLOT
(
)

CIRCULAR_STRUTS_PLOT CIRCULAR_STRUTS_PLOT
(
)

ORIGIN COOR_SYS
(
)

SUB_PATT COOR_SYS
(
ORIGIN : STRUCT(X: 0.000000000 in,Y: 0.000000000 in,Z: 0.000000000 in),
X_AXIS : STRUCT(X: 1.000000000 ,Y: 0.000000000 ,Z: 0.000000000 ),
Y_AXIS : STRUCT(X: 0.000000000 ,Y: -1.000000000 ,Z: 0.000000000 ),
BASE : REF (ORIGIN)
)
FREQS FREQUENCY
(
LIST_FREQ : SEQUENCE( 14.4 GHz)
)

GAUSSIAN_FEED GAUSSIAN_FEED
(
TAPER_ANGLE : 50,
TAPER : -14,
POLARISATION: linear_y
)

GAUSSIAN_FEED_1 FEED
(
FREQUENCY : REF(FREQS),
COOR_SYS : REF(ORIGIN),
FEED_DEFINITION: REF (GAUSSIAN_FEED)
)
GAUSSIAN_PO_SUB STANDARD_PO
(
FREQUENCY :REF(FREQS),
SCATTERER :REF(SUB_REFLECTOR),
PO_POINTS :STRUCT(PO1: 36,PO2: 36),
FILE_NAME :"01-GAUSSIAN_SUB_PO.CUR"
)

GAUSSIAN_PO_MAIN STANDARD_PO
(
FREQUENCY : REF(FREQS),
SCATTERER : REF(MAIN_REFLECTOR),
PO_POINTS :STRUCT(PO1: 237,PO2: 237),
FILE_NAME :"01-GAUSSIAN_MAIN_PO.CUR"
)

GAUSSIAN_FEED_PATTS SPHERICAL_CUT
(
FREQUENCY : REF(FREQS),
THETA_RANGE : STRUCT(START:-70,END: 70,NP: 721),
PHI_RANGE : STRUCT(START: 0,END: 90,NP: 1),
POLARISATION: LINEAR,
FILE_NAME : "01-GAUSSIAN_FEED_PATTS.CUT",
COMMENT : "manpack_01-GAUSSIAN_FEED_PATTERNS - GAUSSIAN FEED"
)

GAUSSIAN_FEED_SUB_PATTS SPHERICAL_CUT
(
FREQUENCY : REF(FREQS),
COOR_SYS : REF(SUB_PATT),
THETA_RANGE : STRUCT(START:-90,END: 90,NP: 1441),
PHI_RANGE : STRUCT(START: 0,END: 90,NP: 1),
POLARISATION: LINEAR,
FILE_NAME : "GAUSSIAN_FEED_SUB_PATTS.CUT",
COMMENT : "SCATTERING PATTERNS FROM SUBREFLECTOR - GAUSSIAN FEED"
)

GAUSSIAN_FEED_MAIN_PATTS SPHERICAL_CUT
(
FREQUENCY : REF(FREQS),
THETA_RANGE : STRUCT(START:-90,END: 90,NP: 1441),
PHI_RANGE : STRUCT(START: 0,END: 90,NP: 1),
POLARISATION: LINEAR,
FILE_NAME : "01-GAUSSIAN_FEED_MAIN_PATTS.CUT",
COMMENT : "ANTENNA RADIATION PATTERNS - GAUSSIAN FEED"
)

GAUSSIAN_FEED_TOTAL_PATTS SPHERICAL_CUT
(
FREQUENCY : REF(FREQS),
THETA_RANGE : STRUCT(START:-90,END: 90,NP: 1441),
PHI_RANGE : STRUCT(START: 0,END: 90,NP: 1),
POLARISATION: LINEAR,
FILE_NAME : "GAUSSIAN_FEED_TOTAL_PATTS.CUT",
COMMENT : "ANTENNA RADIATION PATTERNS - GAUSSIAN FEED"
)

RAY_PLOT RAY_PLOT
(
THETA_RANGE : STRUCT(START: -90.00000000 ,END: 90.00000000 ,NP: 101),
PHI_RANGE : STRUCT(START: -90.00000000 ,END: 90.00000000 ,NP: 101),
RAY_PATH_RANGE : STRUCT(START: 0.000000000 m,END: 0.000000000 m)
)

ASSY D3_PLOT
(
PLOT_ACCURACY : 0.1000000000E-02 m,
FILE_NAME : "ASSY.DXF"
)
MAIN_APERTURE_FIELD_DISTRIBUTION plane_field_grid
(
FREQUENCY : REF(FREQS),
COOR_SYS : REF(ORIGIN),
near_dist : 12.2692307692308 in,
grid_type : xy,
x_range : struct(start:-19.5 ,end: 19.5 ,np: 79,unit: in),
y_range : struct(start:-19.5 ,end: 19.5 ,np: 79),
POLARISATION: LINEAR,
FILE_NAME : "Main_Reflector_Near-Field_Grid.grd"
)
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
After Pasting Code to column A at Excel Try this Code:
VBA Code:
Option Explicit
Sub SplitTextFile()
Dim i As Long, Lr As Long, j As Long, K As Long, C As Long, Cr As String

Lr = Cells(Rows.Count, 1).End(xlUp).Row
j = 1
For i = 1 To Lr
Cr = Cells(i, j).Value
If Cr = "(" Then Cells(i, j).ClearContents
If Cr = ")" Then
Cells(i, j).ClearContents
On Error GoTo Skip
Range(Cells(i + 1, j), Cells(Lr, j)).SpecialCells(xlCellTypeConstants, 23).Copy Cells(1, j + 3)
Range(Cells(i + 1, j), Cells(Lr, j)).ClearContents
j = j + 3
i = 1
End If
Next i
Skip:
Err.Clear
K = j
For j = 1 To K Step 3
Lr = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To Lr
Cr = Cells(i, j).Value
Select Case Right(Cr, 1)
Case ":", ","
Cr = Left(Cr, Len(Cr) - 1)
Cells(i, j).Value = Cr
End Select
On Error GoTo Resum
C = InStr(Cr, ":")
If C > 0 Then
Cells(i, j).Value = Left(Cr, C - 1)
Cells(i, j + 1).Value = Right(Cr, Len(Cr) - C)
End If
Resum:
Next i
Next j
K = Cells(1, Columns.Count).End(xlToLeft).Column
Range(Cells(1, 1), Cells(1, K)).EntireColumn.AutoFit
End Sub
 
Upvote 0
Wow! I spent months trying to do this on my own.
Obviously I am not as experienced in VBA programming as I need to be for this.

Thank you & Best Regards
 
Upvote 0
if you want also separate these Block.
x_range : struct(start:-19.5 ,end: 19.5 ,np: 79,unit: in), to
x_range struct start:-19.5 end 19.5 np 79 unit in
I don't do it, because I think you want these together and only separate with :
If you want to separate , please clarify the exact separation for this example to I add it to code
 
Upvote 0
x_range & struct & start & -19.5 & end & 19.5 & np & 79 & unit & in
 
Upvote 0

Forum statistics

Threads
1,215,391
Messages
6,124,673
Members
449,178
Latest member
Emilou

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