[opensource] Command line question

Drew Yates yates at cse.ohio-state.edu
Sun Jun 4 12:56:34 EDT 2006


Thanks, guys!

On 6/4/06, Jim Dinan <dinan at cse.ohio-state.edu> wrote:
>
> William R. Lorenz wrote:
> > 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.
>
> It looks like that script skips every 16th line rather than joining
> every 15.  If you want to do the latter, you might need to do something
> like:
>
> ---(snip)---
>
> if ($i ne 15)
> {
>         chomp;
>         print FILEO "$_ ";
> } else
> {
>         print FILEO;
>         $i = 0;
> }
>
> ---(snip)---
>
> ... and just to be a pain in the ass, here is the compulsory one-liner:
>
> perl -pe '($. % 16 != 0) and s/\n/ /'
>
> :)
>
> - jim.
>
> --
> James Dinan <dinan at cse.ohio-state.edu>
>
> Graduate RA - Computer Science and Engineering
>               The Ohio State University
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.cse.ohio-state.edu/pipermail/opensource/attachments/20060604/31cb688a/attachment.html


More information about the Opensource mailing list