Need help to fetch data from raw file

Hi Friends,

Im new new to python. I need help to fetch data from raw file as below. please any one share me the code im confused totally

raw file:
config firewall policy
edit 972
set name “730082”
next
edit 1027
set name “79176”
set uuid 6046533a-4646-51ed-d5e3
next
edit 926
set name “5058”
set uuid 1564f002-fd16-51ec-3527
next
edit 999
SET DDS
edit 1027
set name “duplicate”

Expection: need to pull data using edit (ID).
my inputs: 972 , 926

expected output:
edit 972
set name “730082”
next
edit 926
set name “5058”
set uuid 1564f002-fd16-51ec-3527
next

In pseudocode it’s this:

Open the raw file and the output file.

Iterate over the lines of the raw file:

    If the line starts with 'edit ':

        If the number after it is one of the input numbers:

            Write that line to the output file.

            Copy lines from the raw file to the output file until the line starts with 'next'.

        Otherwise:

            Read lines from the raw file until the line starts with 'next'.