I'm trying to get gawk to split a text file into a different file each time a paragraph contains an occurrence of a code of the form "7-04/PNLP-000001". So, for instance, if the original text file contains the following:
Proposición no de Ley 7-04/PNLP-000009, relativa a la línea Ave Sevilla-Córdoba-Madrid.
La señora PRESIDENTA
Proposición no de Ley 7-04/PNLP-000001, relativa a la restitución y mejora de los derechos y la cobertura social de los trabajadores del medio rural andaluz.
La señora PRESIDENTA
I would like to get a file with this content:
Proposición no de Ley 7-04/PNLP-000009, relativa a la línea Ave Sevilla-Córdoba-Madrid.
La señora PRESIDENTA
and another with this content:
Proposición no de Ley 7-04/PNLP-000001, relativa a la restitución y mejora de los derechos y la cobertura social de los trabajadores del medio rural andaluz.
La señora PRESIDENTA
I'm trying to to this with this code:
gawk '
/^\n.+[0-9]\-[0-9]{2}\/.+\-[0-9]{6}$/
{if (p) close (p)
p = sprintf("split%05i.txt", ++i) }
{ print > p; }
' input.txt
However, this just creates one file per line, whatever its content. Does anyone know what I'm doing wrong? Thanks in advance!