copy lines matching a regex to another document

I have a huge text file containing 384 firewall rules written up as this:

Rule 1 LAN -> LAN Allow Service Any -> SSH Management (Enabled)
       IP: Any -> All X0 Management IP  Iface: Any (ffffffff) -> Any (ffffffff) 
Policy Name:               
UUID:                      bfc907b9-b13b-05eb-0700-c0eae481e2c2
Instance:                  13819585425686857195
Logging:                   Enabled         Management: Enabled
Allow Fragmented Packets:  Enabled         Packet Monitor: Disabled
Flow Reporting:            Disabled
Auto Rule:                 Disabled
Users:                     Included: All,  Excluded: None
Schedule:                  Always on (on)
Comment:                   Auto-added management rule
Timeout:                   TCP:5 minutes,  UDP:30 seconds
IP Version:                IPv4
Properties:                0xffeffd,  Priority Type: Manual
Max Connections:           100% of maximum connections
Connections:               1
Src IP connection limit:   128 (off)
Dst IP connection limit:   128 (off)
Geo IP Block:              0
Per Policy Geo IP Block:   0
Per Policy Geo IP Bitmap:  
Per Policy Block Unknown:  0
Botnet Block:              0
Bypass DPI:                No
Bypass DPI-SSL Client:     No
Bypass DPI-SSL Server:     No
Qos Marking DSCP Action:   Preserve
Qos Marking 802.1p Action: None
Egress BWM:	Disabled

Ingress BWM:	Disabled

Tracking Bandwidth Usage:	Disabled
Bytes, Packets:            Rx: 2640, 60    Tx: 5612, 122
Usage                     : 389
Time Created:    07/05/2019 11:05:11.000
Time Updated:    12/04/2019 21:59:23.000
Time Config Updated:    07/05/2019 11:05:11.000
Time Last Hit:   02/17/2020 09:08:27.000

And I need only the first two lines of each rule (there 750 of these rules).

Rule 1 LAN -> LAN Allow Service Any -> SSH Management (Enabled)
       IP: Any -> All X0 Management IP  Iface: Any (ffffffff) -> Any (ffffffff) 

I know I could use regex or macros to do something like this but I don’t know how to tackle that issue, especially how to match with a regex anything after Rule [number], including the second line, without matching anything else.

I also have no idea what functions to use in the macro to then export al matches to a new file, preferrably a libreoffce calc file, from which I could then keep formatting them with simpler macros and regex until I have something workable.

any help or direction would be highly appreciated, thanks!

Try if this example works for you.
If so copy the code to a module in the Standard library of your source file or to your local Basic container and run it for your actual source file.

===Editing 2020-02-18 about 10:00 UTC===
This is the code:

Sub copyHeaderLinesToSheet() 's... four Source, t... for Target.
sDoc    = ThisComponent
sUrl    = sDoc.Url
splUrl  = Split(sUrl, "/") : u = Ubound(splUrl)
foP     = Left(sUrl, Len(sUrl)-Len(splUrl(u)))
tUrl    = foP & "rules.ods"
sText   = sDoc.Text
cCtrl   = sDoc.CurrentController
oldSel  = sDoc.CurrentSelection
sDesc   = sDoc.createSearchDescriptor()
sDesc.SearchRegularExpression = True
sDesc.SearchString            = "Rule +\d+"
found   = sDoc.FindNext(sText.Start, sDesc)
tDoc    = StarDesktop.LoadComponentFromUrl("private:factory/scalc", "_blank", 0, Array())
tSheet  = tDoc.Sheets(0)
r       = 0
k       = 0
vc      = cCtrl.ViewCursor
Do until IsNull(found)
  k               = k + 1
  cCtrl.select(found.Start)
  vC.goToEndOfLine( True)
  line1           = vc.String
  tCell           = tSheet.getCellByPosition(0, r)
  tCell.String    = line1
  cCtrl.select(vc.End)
  vC.goRight(1, False)
  vC.goToEndOfLine( True)
  line2           = vc.String
  tCell           = tSheet.getCellByPosition(0, r+1)
  tCell.String    = line2
  r               = r + 2
  found           = sDoc.FindNext(found, sDesc)
Loop
tDoc.storeAsUrl(tUrl, Array())
MSgBox(k & " rules processed.")
'tDoc.Close(True)
cCtrl.select(oldSel)
End Sub

thank you very much, you are a savior! I can now work this on my own to get it where I need it, I wouldn’t have been able to write such a macro myself from scratch.
thanks!

This does not answer the question. Please delete and use add a comment.

And please, if the answer solves the question click :heavy_check_mark:.

I’d simply extract each first two rows of the text file before importing:

grep -A1 '^Rule ' textfile | grep -v '^--' > textfile2.csv