Re: need a newline between paragraphs....
On Wed, Nov 25, 2009 at 01:08:39PM -0700, Chad Perrin wrote: > On Tue, Nov 24, 2009 at 01:19:42PM -0800, Gary Kline wrote: > > On Tue, Nov 24, 2009 at 01:07:41PM -0700, Chad Perrin wrote: > > > > precisely. in this case, every paragraph that is not on a > > newline wraps. so anything that has an EOL is a new > > paragraph. > > If I understand you correctly, the following should work for your > purposes (as a naive implementation of the concept): > > my $contents; > > { > undef $/; > open(my $fh, '<', $in_filename) or die $!; > $contents = <$fh>; > } > > $contents =~ s/\n+/\n\n/g; > > { > open(my $fh, '>', $out_filename) or die $!; > print($fh $contents); > } > > That assumes that you want to turn any and all instances of one or more > consecutive newlines into exacty two newlines. More finagling might be > required if there may be other adjacent whitespace, which would need to > account for not only possible adjacent whitespace but also possible > whitespace at the beginning of a line with other text on it. Maybe > something like this: > > $contents =~ s/\s*\n+/\n\n/g; > > . . . though I haven't thought it through in too much depth with regards > to the implications in edge case circumstances (thus the "naive > implementation" comment above). > Turns out that the problem was resolved by the print $fh "$_$/"; or close to that. Since I scrubbed 100% of newlines -- and axing all whitespace before and after lines -- before handing off the large file to OpenOffice, there wasn't any concern about extra whitespace messing stuff up. > > > > > there are a few places that require different formatting; > > these are easily re-done thanks to OOo! > > I'm the kind of guy who would look for a way to automate things so that > re-formatting in OOo wouldn't be necessary, but as long as you're happy, > I guess we win. Good luck! > Hm. Y'know, if *somebody* would just make having vim as an option along with OOo, along with wrapping all the lines, life would be (abs)Perfect. I would nevr complain about anything; not ever. My fingers know vi; I've used vi since BillJoy invented it and handed me the first docs. It only took a couple weeks to learn, and I still don't know all the tricks. But enough to do what I *NEED* to, and with fewer fumbles _(or hurting my arm/shoulder that using the word-processor with mouse + keybd). having scripts to switch between file and file.txt|.odt gets pretty close :-) thanks much, gary > -- > Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org The 7.31a release of Jottings: http://jottings.thought.org/index.php ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: need a newline between paragraphs....
On Tue, Nov 24, 2009 at 01:19:42PM -0800, Gary Kline wrote: > On Tue, Nov 24, 2009 at 01:07:41PM -0700, Chad Perrin wrote: > > precisely. in this case, every paragraph that is not on a > newline wraps. so anything that has an EOL is a new > paragraph. If I understand you correctly, the following should work for your purposes (as a naive implementation of the concept): my $contents; { undef $/; open(my $fh, '<', $in_filename) or die $!; $contents = <$fh>; } $contents =~ s/\n+/\n\n/g; { open(my $fh, '>', $out_filename) or die $!; print($fh $contents); } That assumes that you want to turn any and all instances of one or more consecutive newlines into exacty two newlines. More finagling might be required if there may be other adjacent whitespace, which would need to account for not only possible adjacent whitespace but also possible whitespace at the beginning of a line with other text on it. Maybe something like this: $contents =~ s/\s*\n+/\n\n/g; . . . though I haven't thought it through in too much depth with regards to the implications in edge case circumstances (thus the "naive implementation" comment above). > > there are a few places that require different formatting; > these are easily re-done thanks to OOo! I'm the kind of guy who would look for a way to automate things so that re-formatting in OOo wouldn't be necessary, but as long as you're happy, I guess we win. Good luck! -- Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] pgp43t6WfPaOl.pgp Description: PGP signature
Re: need a newline between paragraphs....
On Tue, Nov 24, 2009 at 01:07:41PM -0700, Chad Perrin wrote: > On Mon, Nov 23, 2009 at 05:39:35PM -0800, Gary Kline wrote: > > > > PS: is there any one-liner to add back one newline between > > paragraphs? > > As someone else said -- that depends on how you define a "paragraph" in > the file. If any time there's a newline you've got a new paragraph, you > can just use a simple substitution regex to replace all instances of one > newline with two newlines. If some of your paragraphs are already > separated by two newlines, you could just use \n+ in the matching part of > your substitution regex to indicate that you want any instance of one or > more newlines in succession to be replaced with exactly two newlines -- > if that doesn't screw up some other formatting you have in the file. > > In order to answer this question properly, we'd need to know more about > how you define "paragraph" in this context, and whether there are special > cases of non-paragraph formatting that might cause conflicts with > paragraph formatting while doing a substitution. > precisely. in this case, every paragraph that is not on a newline wraps. so anything that has an EOL is a new paragraph. there are a few places that require different formatting; these are easily re-done thanks to OOo! > -- > Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org The 7.31a release of Jottings: http://jottings.thought.org/index.php ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: need a newline between paragraphs....
On Tue, Nov 24, 2009 at 07:09:34PM +0200, Giorgos Keramidas wrote: > On Mon, 23 Nov 2009 17:39:35 -0800, Gary Kline wrote: > > PS: is there any one-liner to add back one newline between paragraphs? > > Not an accurate one. > > You can *guess* when a line ends with a punctuation character > *and* it is shorter than some configurable wrapping column that > it is probably the end of a paragraph. But this is only a > heuristic guess and a pretty silly heuristic at that. > it's prob'ly bcse i'm older than zeus, but it seems that i once wrote a script or short c program that detected the end-of-paragraph. maybe somewhere in atom. anyway, karl vogel came to my rescue with a two-byte change to the print $fh "$_"; line. appending "$/" resolves the problem. print $fh "$_$/"; now i can point kttsd's reader at the entire [huge] file -- while i read along. or read each chapter individually. the way i wrote them -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org The 7.31a release of Jottings: http://jottings.thought.org/index.php ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: need a newline between paragraphs....
On Mon, Nov 23, 2009 at 05:39:35PM -0800, Gary Kline wrote: > > PS: is there any one-liner to add back one newline between > paragraphs? As someone else said -- that depends on how you define a "paragraph" in the file. If any time there's a newline you've got a new paragraph, you can just use a simple substitution regex to replace all instances of one newline with two newlines. If some of your paragraphs are already separated by two newlines, you could just use \n+ in the matching part of your substitution regex to indicate that you want any instance of one or more newlines in succession to be replaced with exactly two newlines -- if that doesn't screw up some other formatting you have in the file. In order to answer this question properly, we'd need to know more about how you define "paragraph" in this context, and whether there are special cases of non-paragraph formatting that might cause conflicts with paragraph formatting while doing a substitution. -- Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] pgph68SyEyeB2.pgp Description: PGP signature
Re: need a newline between paragraphs....
On Mon, 23 Nov 2009 17:39:35 -0800, Gary Kline wrote: > PS: is there any one-liner to add back one newline between paragraphs? Not an accurate one. You can *guess* when a line ends with a punctuation character *and* it is shorter than some configurable wrapping column that it is probably the end of a paragraph. But this is only a heuristic guess and a pretty silly heuristic at that. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: need a newline between paragraphs....
Gary Kline wrote: > PS: is there any one-liner to add back one newline between > paragraphs? That depends a lot on how you define paragraph. If they all start with tabs, something like: sed '/^<^VTAB>/ i\ \<^VTAB> ' myfile Where you use ^VTAB to insert some literals tabs on the commandline. I couldn't seem to convince sed to insert an empty line, but I didn't play around with it all that long. If you need more sophisticated paragraph detection (like based on the previous line not being some number of characters or some kind of period to capital letter thing or something), you're going to spend a lot more time mucking through it. -- Chris Cowart Network Technical Lead Network & Infrastructure Services, RSSP-IT UC Berkeley pgpUdCgaJ96xC.pgp Description: PGP signature
Re: need a newline between paragraphs....
On Mon, Nov 23, 2009 at 04:36:52PM -0800, Chris Cowart wrote: > Gary Kline wrote: > > some several weeks ago, i got the appended perl code sent that > > takes a very long txt file and diving by ``Chapter NN'' puts > > the long file into seperate files, 01 to 66. trouble is that > > it is hard to read by eyes without a space between paragraphs. > > > > it's easy for grep to remove all newlines. How do i add them > > back? > [...] > > # We've read at least one chapter heading. > > while (<>) { > > chomp; > > $fh = newchapter($1) if /$regex/; > next if /^#/; > > It looks like this line of code is killing the blank lines. If you > delete the line and re-run the program, you should be good to go. If you > don't have the original anymore, it'll be a lot harder and much less > accurate. > > Good luck, > thanks; you were right on the money. i think that by doing a grep -v "^$" <> all blank lines are scotched. in this perl script, the syntax didn't catch my eye. at least that's my excuse... . anyway, axeing that line did the trick; now i can chapterize my book from the huge text file. gary PS: is there any one-liner to add back one newline between paragraphs? > -- > Chris Cowart > Network Technical Lead > Network & Infrastructure Services, RSSP-IT > UC Berkeley -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org The 7.31a release of Jottings: http://jottings.thought.org/index.php ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: need a newline between paragraphs....
Gary Kline wrote: > some several weeks ago, i got the appended perl code sent that > takes a very long txt file and diving by ``Chapter NN'' puts > the long file into seperate files, 01 to 66. trouble is that > it is hard to read by eyes without a space between paragraphs. > > it's easy for grep to remove all newlines. How do i add them > back? [...] > # We've read at least one chapter heading. > while (<>) { > chomp; > $fh = newchapter($1) if /$regex/; > next if /^#/; It looks like this line of code is killing the blank lines. If you delete the line and re-run the program, you should be good to go. If you don't have the original anymore, it'll be a lot harder and much less accurate. > print $fh "$_"; > } Good luck, -- Chris Cowart Network Technical Lead Network & Infrastructure Services, RSSP-IT UC Berkeley pgp51hzqyX77C.pgp Description: PGP signature
need a newline between paragraphs....
some several weeks ago, i got the appended perl code sent that takes a very long txt file and diving by ``Chapter NN'' puts the long file into seperate files, 01 to 66. trouble is that it is hard to read by eyes without a space between paragraphs. it's easy for grep to remove all newlines. How do i add them back? tia gary PS: having long, wrapped lines would work best ENCL: txt2chapts.pl #!/usr/bin/perl -w #) { chomp; if (/$regex/) { $fh = newchapter($1); print $fh "$preamble" . "$_"; last; } $preamble .= "$_" . "$/"; } # We've read at least one chapter heading. while (<>) { chomp; $fh = newchapter($1) if /$regex/; next if /^#/; print $fh "$_"; } close($fh); exit(0); # Open a new chapter if we match the regular expression. sub newchapter { my $n = shift || die "need a number"; my $file = sprintf("%2.2d", $n); close($fh) if defined($fh); open($fh, "> $file") or die "$file: $!\n"; return $fh; } /* FWIW: here are a few paragraphs from chapter one */ Chapter One "We're here," Erik said to his date as he swung his van into the diabled slot of the Blue Note Tavern's parking lot. For the slightest moment he was awkstruck at how pretty she was. That the girl was blind meant nothing to Erik. She could've been blind, deaf, and missing her right leg. The only thing he was certain of was that he wanted her--maybe worse that he'd wanted anything. *Ever.* The radio interrupted with the weather forecast just then. "It's cold out there, folks, so bundle up! It's 21 degrees here in Pine Falls, but the wind chill is a brisk minus 23 to around 40 degrees. Now the forecast for all of Northwest Wisconsin: From 10 to 20 degrees with dangerously cold wind chills ranging to minus 40 degrees. Less windy and much warmer tomorrow and even warmer on Sunday." "Typical November weather," he said, but no problem," he said. "We're right by the front door!" "You're in a wheelie spot?" she asked. "You bet!" Dawn said, "My brother Morgan says it's wrong to have this. He thinks it's reverse discrimination; that whoever gets to the nearest parking space first ought to get it. I tell him, God forbid he should ever be disabled!" ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"