From: Harry on
I have an input text file like this.
------------------------
DEFINE QLOCAL ('Q1') +
... number of lines
...
REPLACE

DEFINE QLOCAL ('Q2') +
... number of lines
...
REPLACE

DEFINE QALIAS ('A1') +
... number of lines
...
REPLACE

DEFINE QALIAS ('A2') +
... number of lines
...
REPLACE

------------------------

The input file contains other definitions as well, such as
QREMOTE, LISTENER, etc. But I use the above for the sake
of simplicity.

I want to split the conent of this input file so that
each segment (record) of text (blank line as record separator)
will be copied to text files, like this :

../QLOCAL/Q1 <-- the define statement as file content
../QLOCAL/Q2
../QALIAS/A1
../QALIAS/A2

That is, the subfolder is the name (QLOCAL or QALIAS) after
the word DEFINE. While the filename corresponds to the string
surrounded by ('<as_filename>').

Appreciate your help.
From: Janis Papanagnou on
On 13/08/10 00:19, Harry wrote:
> I have an input text file like this.
> ------------------------
> DEFINE QLOCAL ('Q1') +
> ... number of lines
> ...
> REPLACE
>
> DEFINE QLOCAL ('Q2') +
> ... number of lines
> ...
> REPLACE
>
> DEFINE QALIAS ('A1') +
> ... number of lines
> ...
> REPLACE
>
> DEFINE QALIAS ('A2') +
> ... number of lines
> ...
> REPLACE
>
> ------------------------
>
> The input file contains other definitions as well, such as
> QREMOTE, LISTENER, etc. But I use the above for the sake
> of simplicity.
>
> I want to split the conent of this input file so that
> each segment (record) of text (blank line as record separator)
> will be copied to text files, like this :
>
> ./QLOCAL/Q1 <-- the define statement as file content
> ./QLOCAL/Q2
> ./QALIAS/A1
> ./QALIAS/A2
>
> That is, the subfolder is the name (QLOCAL or QALIAS) after
> the word DEFINE. While the filename corresponds to the string
> surrounded by ('<as_filename>').
>
> Appreciate your help.

If the directories are already existing

awk -v q="'" -v RS= '{ split($3,f,q); print > $2"/"f[2] }'

If awk shall also create the directories

awk -v q="'" -v RS= '
{ split($3,f,q); system("mkdir -p "$2); print > $2"/"f[2] }'


Janis
From: Harry on
On Aug 12, 4:17 pm, Janis Papanagnou <janis_papanag...(a)hotmail.com>
wrote:

> If the directories are already existing
>
>   awk -v q="'" -v RS= '{ split($3,f,q); print > $2"/"f[2] }'
>
> If awk shall also create the directories
>
>   awk -v q="'" -v RS= '
>       { split($3,f,q); system("mkdir -p "$2); print > $2"/"f[2] }'
>

Cool.
Thanks