One liner? --- split file at empty line

Hi,

···

At Fri, 18 Oct 2002 08:08:01 +0900, Dong wrote:

I need to split a file

Part A

Part B

to files A, B, …

ruby -slne ‘open($1,“w”){|f|f.puts $_}if/\APart\s+(\S+)/’ – -/=

No standard command line option to make paragraph mode…


Nobu Nakada

Hi,

···

At Fri, 18 Oct 2002 08:55:02 +0900, nobu.nokada@softhome.net wrote:

No standard command line option to make paragraph mode…

Sorry, I forgot -00 option.

$ ruby -00lne ‘open($1,“w”){|f|f.puts $_}if/\APart\s+(\S+)/’


Nobu Nakada

Thanks. It looks good to me. But it is missing the first Part.
The file looks like:

Some header
Part Cu

Part In

Part O

Part Se

So far I got file In, O, and Se, but not Cu.

Dong

···

On Mon, 21 Oct 2002 07:12:21 +0900, nobu.nokada@softhome.net wrote:

$ ruby -00lne ‘open($1,“w”){|f|f.puts $_}if/\APart\s+(\S+)/’

Hi,

···

At Mon, 21 Oct 2002 11:32:48 +0900, Dong wrote:

Thanks. It looks good to me. But it is missing the first Part.
The file looks like:

Some header

I assumed each part start with “Part” line. If preceeding
lines exist, replace ‘\A’ with ‘^’.


Nobu Nakada

Thanks. Apparently I did not understand the meaning of string – I thought
it is part of a line.

Now it works great. I do have another question: My data files are named
like 30.txt, 40.txt. How can I generate files with name Cu30.txt, In30.txt?
Where is the arguement stored? I guess I only need to substitute $1 with
$1 + filename)

ruby -00lne ‘open($1,“w”){|f|f.puts $_}if/\APart\s+(\S+)/’ 30.txt

Dong

···

On Mon, 21 Oct 2002 11:56:37 +0900, nobu.nokada@softhome.net wrote:

I assumed each part start with “Part” line. If preceeding
lines exist, replace ‘\A’ with ‘^’.

Hi,

···

At Mon, 21 Oct 2002 13:32:58 +0900, Dong wrote:

Now it works great. I do have another question: My data files are named
like 30.txt, 40.txt. How can I generate files with name Cu30.txt, In30.txt?
Where is the arguement stored? I guess I only need to substitute $1 with
$1 + filename)

ARGF.filename


Nobu Nakada