word rap?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



1.  This is off topic.

2.  No.

3.  Sort of.  I had to reformat a document yesterday, and managed it
by being rather creative with tr, cut, and nano's word wrap.

IIRC, I used cut to remove extraneous whitespace at the start of lines.  I
then used nano to enter the file, press space, backspace, down arrow,
space, backspace, down arrow (rince and repeat), to cause nano to wrap
each line at the screen boundry (this file had _very!_ long lines).
Since I wanted a greater then sign at the begining of each line (I wanted
to use the article in a point by point reply to an email message), I used
tr to exchange all new line characters for a dollar sign (not a common
character in this document), nano to do a global (without prompting)
search-and-replace, thus changing "$" to "$> ", after first turning nano's
word wrap off (escape w).
I then emploied tr again, to reverce my dollar sign conversion, and bingo.

I am reasonably sure, that if I was still proficient in awk, or had ever
managed to get sed to work on anything (the one big unix mystery I have
yet to solve, is to get sed to do the simplest thing based upon the man
page instructions), but I didn't have the time to relearn, or try to
debug, awk, so just used the method above.  A bit tedious, but it worked.

This would have been much easier, if I had taken the time to move the file
to a web server, and write a PHP script to deal with it--the
areg_replace(), and wordwrap(), functions, would have worked wonders on
this file, but there was no php on the local machine, and for some reason,
it didn't occurr to me until just now, that I could have moved the file to
one of the web servers, and done it there.

With awk, or maybe perl, you could do something like this:

* use the standard whitespace field seperators.
* add a word at a time to a string.
* count the characters in each word prior to adding it.
* If the word would take you past 80 characters, output your string,
insert  a new line, and reset the count.
* If not, add the word, and update the count.
* If the next fs is a space, determine if 1 will take the count to 80 or
above.  If so, nl and reset, dumping the space.
* If the next fs is a tab, do the same by adding 8.
* If the fs is a nl, output the string and nl, and reset the count.

I probably missed a condition, and this has no error checking (single
words that are 80 plus characters in length), but you should have enough
of  an idea of the logic, to write it in C, awk, PERL, flex (does anyone
still  use that?), or the language of your choice.

Luke





On Sat, 11 May 2002, Jim Stevenson wrote:

> Can ed or ex be set to word rap?
>
> Can col or what else insert <cr> for the last space before column 80?
>
> What if I want a longer line length like 120?
>
> If you must quote me, please put your comments first.
> I have already listened to mine.
>
> I read email with speech.
> So it is not possible to scroll past the quotes without listening to them again,
> to quickly get to the new information.
>
> Thanks.
>
>
>
> _______________________________________________
> 
> Blinux-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/blinux-list
>

-- 
P.S. If you are interested in a free business opportunity with great
potential, please drop me a line.





[Index of Archives]     [Linux Speakup]     [Fedora]     [Linux Kernel]     [Yosemite News]     [Big List of Linux Books]