[TriLUG] vi or sed or perl question - joining lines
Owen Berry
oberry at trilug.org
Mon Jun 4 14:15:19 EDT 2007
On Fri, Jun 01, 2007 at 02:33:46PM -0400, Alan Porter wrote:
>
> > I have a big goofy text file I need to get into a more usable format.
> > Basically what I need to do is join every 12 lines into 1 line, down
> > through the entire file. Does anyone have a good suggestion on how to do
> > this? I know that I must have done this same thing 2 years ago, because I
> > found an earlier version of this same data from May 2005 that I somehow
> > converted, but I now have no idea how it was done.
> >
>
> It might sound wacky, but I would start by echo-ing "12Jj12Jj12Jj" onto
> an xterm a dozen times. Then cut that with the mouse and paste it into
> your vi session. It's a hack, but it works pretty well. Slow down
> towards the end of the file.
>
> Alan
It's a little late, but I'm catching up with mail after being away for a
week. A cleaner way would be to use a vim macro:
qa (start recording macro 'a')
12J (do the joining)
j (move down one line)
q (stop recording macro)
10 at a (replay macro 10 times, or however many desired)
Lovely stuff vim macros, and useful for all kinds of things.
Owen
More information about the TriLUG
mailing list