On Thu, Dec 15, 2005 at 11:03:35PM +0000, Braun Brelin wrote:
> Okay,
>> so i'm trying to figure a regular expression to do the following:
>> Take a single (really long) line and break it up into 80 character
> lines. i.e. after every 80th character, insert a newline (or, if it's
> HTML) insert a <br>
fold < file.in > file.out
Not exactly a regex. If you're in vim you can also use the gggqG to wrap
all the lines in the file. gqJ will do the current line.
':set textwidth=80' is the default.
For the <br> I'd pipe it through sed -e 's/$/<br>/'.
Vim line is ':%s /$/<br>/', not exactly what you asked for though.
For perl: 'perl -pe "s/(.{80})/\1\n/g"' works, although it doesn't handle
lines of length 80*n correctly.
perl -pe 's/^(.{80})(.+)/\1\n\2/' will handle it correctly, but you
might need to run it a few times. A while loop on the substitution
should handle that.
Substitute <br> in the above for /n for HTML.
Brian
--
Website: http://www.netsoc.tcd.ie/~bbrazil
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!