mardi 9 août 2022

parse from a huge txt file and write each output in separate files

How can I extract a multiline string from a huge txt file and to write each found pattern in a separate file?

An example extract from source file (example.txt):

RIG 1C 0
RIC 1 F
RIB F F
RIB A F
RIB O O
RIC 2 C
RIB J J
RIB C J
RIB D C
RIB Z D
RIB R Z
RIB I I
RIB S S
RIC 3 Y
RIB Y Y
RIB M Y
RIB L M
RIB H L
RIB K H
RIB B K
RIB W B
RIB Q W
RIB V Q
RIB N V
RIB G B
RIB T B
RIB X X
RIG 1C 1
RIC 1 F
RIB F F
RIB A F
RIB O O
RIC 2 C
RIB J J
RIB C J
RIB D C
RIB Z D
RIB R Z
RIB I I
RIB S S
RIC 3 Y
RIB Y Y
RIB M Y
RIB L M
RIB H L
RIB K H
RIB B K
RIB W B
RIB Q W
RIB V Q
RIB N V
RIB G B
RIB T B
RIB X X
RIG DE 0
RIC 1 F
RIB F F
RIC 2 C
RIB C C

Pattern is from RIG to RIG

this means first file RIG1C0.txt contains:

RIG 1C 0
RIC 1 F
RIB F F
RIB A F
RIB O O
RIC 2 C
RIB J J
RIB C J
RIB D C
RIB Z D
RIB R Z
RIB I I
RIB S S
RIC 3 Y
RIB Y Y
RIB M Y
RIB L M
RIB H L
RIB K H
RIB B K
RIB W B
RIB Q W
RIB V Q
RIB N V
RIB G B
RIB T B
RIB X X

second file RIG1C1.txt :

RIG 1C 1
RIC 1 F
RIB F F
RIB A F
RIB O O
RIC 2 C
RIB J J
RIB C J
RIB D C
RIB Z D
RIB R Z
RIB I I
RIB S S
RIC 3 Y
RIB Y Y
RIB M Y
RIB L M
RIB H L
RIB K H
RIB B K
RIB W B
RIB Q W
RIB V Q
RIB N V
RIB G B
RIB T B
RIB X X

and so on.

I heard something about RegEx

Is someone able to help me?

Aucun commentaire:

Enregistrer un commentaire