[opensource] Command line question

William R. Lorenz wrl at express.org
Sun Jun 4 01:31:00 EDT 2006


Hi Drew,

The following code will join together every 15 lines:

 	#!/usr/bin/perl

 	open(FILEI,"<file.i"); # in
 	open(FILEO,">file.o"); # out

 	for ($i = 0; <FILEI>; $i++)
 	{
 	        if ($i ne 15)
 	        {
 	                print FILEO $_;

 	        } else
 	        {
 	                $i = 0;
 	        }
 	}

 	close(FILEI);
 	close(FILEO);

If you want to specialize it for newlines, that should be easy enough.

Primitive, but it works. ;)  Hope it helps.

On Sun, 4 Jun 2006, Drew Yates wrote:

>> From a command prompt, how can I:
>
> join together every 15 lines of a file.
>
> that is, 15 newlines will be replaced by a space, then the 16th will be
> skipped, then the next 15 newlines will be replaced... etc.
>
> The furthest I've gotten is join the first 15 lines only using sed. Anyone
> have the solution or some pointers how to solve this elegantly on the
> command line? A bash script or little perl script would work, too.
>
> thanks!
>
> -Drew
>

-- 
William R. Lorenz


More information about the Opensource mailing list