Re: [CentOS] Need to split long lines in mail archives

2012-04-09 Thread Woodchuck
On Mon, Apr 9, 2012 at 1:09 PM, James B. Byrne  wrote:
> CentOS-6.2
>
> I am investigating how to split long lines present in a
> Mailman generated html archives.  Mailman places the email
> bodies within  tags and some users have MUAs
> that send entire paragraphs as one long line.

Such users are usually tough customers, too.  "flowed text"
is the way they assert their personalities, I think.

> I have looked at fmt and fold but these assume a pipeline
> from stdout to a fixed filename, which presumably is best
> done at the time of the original file's creation.  I am
> looking for a way to deal with multiple existing files in
> a batch fashion so that the reformatted file is written
> back out to the same file name oin the same location.

It is very rare to see a Unix utility that operates "in place"
like this.  Off hand, I can't think of any.

> I cannot seem to hit upon a way to get this to work using
> find, xargs and fmt (or fold).  Nor can I seem to find an
> example of how this might be done using these utilities.
>
> What I would like to discover is the functional equivalent
> of this:
>
> find /path/to/archives/*.html -print | xargs -I {} fmt -s
> {} > {}
>
> This syntax does not work of course because the xargs file
> name substitution only occurs once in the initial argument
> list of the following command. But, this example does
> describe the effect I wish to obtain, to have the original
> file name receive the reformatted contents.


Assuming that the fmt utility does what you want,
then you will need a stanza something like this:

fmt -flagswhatever FILENAME >/tmp/mytemp
mv /tmp/mytemp FILENAME

In other words you need a script, not a single pipe.
You want fmt to operate on one file at a time.

find somedir -name "*.html" >/tmp/htmlstuff
for FILENAME in `cat /tmp/htmlstuff`
do
fmt (flags) $FILENAME >/tmp/foo
mv /tmp/foo $FILENAME
done

That's not robust but is just for concept.  More robust scripts
would use "read" to get filenames, and would worry about
embedded blanks in filenames, and other niceties.  A real
script would use mktemp to generate a temp filename.

fmt(1) is not robust, either.  It will format the whole file with
a single-minded determination.  This includes mail headers,
attachments, blah blah.  it might even break the html.  There
are many unexpected consequences.

My advice is to not format these mails.  Why do you want to?
perhaps there is a work-around that meets your goals.

Dave
-- 
"The Earth is a farm. We are someone else's property."  -- Charles Fort
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Need to split long lines in mail archives

2012-04-09 Thread ken
Sounds like you need to loop through a bunch of files and process each 
separately... so:

$!/bin/bash

cd /path/to/archives/
for $f in $(find . -name *.html)
do
fmt -s $f > $f.out
mv $f.out $f  # rename back to original name
done

Untested.  But this is basically what you want to do.  And it's a good 
sort of structure to pick up on.  You'll use it often.


hth,
ken

On 04/09/2012 01:09 PM James B. Byrne wrote:
> CentOS-6.2
>
> I am investigating how to split long lines present in a
> Mailman generated html archives.  Mailman places the email
> bodies within  tags and some users have MUAs
> that send entire paragraphs as one long line.
>
> I have looked at fmt and fold but these assume a pipeline
> from stdout to a fixed filename, which presumably is best
> done at the time of the original file's creation.  I am
> looking for a way to deal with multiple existing files in
> a batch fashion so that the reformatted file is written
> back out to the same file name oin the same location.
>
> I cannot seem to hit upon a way to get this to work using
> find, xargs and fmt (or fold).  Nor can I seem to find an
> example of how this might be done using these utilities.
>
> What I would like to discover is the functional equivalent
> of this:
>
> find /path/to/archives/*.html -print | xargs -I {} fmt -s
> {}>  {}
>
> This syntax does not work of course because the xargs file
> name substitution only occurs once in the initial argument
> list of the following command. But, this example does
> describe the effect I wish to obtain, to have the original
> file name receive the reformatted contents.
>
>
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Need to split long lines in mail archives

2012-04-09 Thread fred smith
On Mon, Apr 09, 2012 at 01:09:59PM -0400, James B. Byrne wrote:
> CentOS-6.2
> 
> I am investigating how to split long lines present in a
> Mailman generated html archives.  Mailman places the email
> bodies within  tags and some users have MUAs
> that send entire paragraphs as one long line.
> 
> I have looked at fmt and fold but these assume a pipeline
> from stdout to a fixed filename, which presumably is best

fold reads stdin and writes stdout. I have a script I use all
the time that depends on that, so I know it works that way.

here's an excerpt from "man fold" on my system:

FOLD(1)  User Commands FOLD(1)

NAME
   fold - wrap each input line to fit in specified width

SYNOPSIS
   fold [OPTION]... [FILE]...

DESCRIPTION
   Wrap input lines in each FILE (standard input by default), writing to 
standard output.


-- 
 Fred Smith -- fre...@fcshome.stoneham.ma.us -
   But God demonstrates his own love for us in this: 
 While we were still sinners, 
  Christ died for us.
--- Romans 5:8 (niv) --
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Need to split long lines in mail archives

2012-04-09 Thread Paul Heinlein

On Mon, 9 Apr 2012, Woodchuck wrote:


fmt -flagswhatever FILENAME >/tmp/mytemp
mv /tmp/mytemp FILENAME


You might find the tidy utility (http://tidy.sourceforge.net/) handy
for this operation. It accepts the "-wrap N" option, which works great
in my toolchains, but I've never tried it on Mailman archives.


fmt(1) is not robust, either.  It will format the whole file with
a single-minded determination.  This includes mail headers,
attachments, blah blah.  it might even break the html.  There
are many unexpected consequences.


tidy won't break the HTML, at least, but there may indeed be 
unintended consequences. Testing suggested. :-)


--
Paul Heinlein
heinl...@madboa.com
45°38' N, 122°6' W___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Need to split long lines in mail archives

2012-04-09 Thread Karl Vogel
>> On Mon, 9 Apr 2012 13:09:59 -0400, 
>> "James B. Byrne"  said:

J> I am investigating how to split long lines present in a Mailman
J> generated html archives.  Mailman places the email bodies within
J>  tags and some users have MUAs that send entire paragraphs as
J> one long line.

   A Perl module called "Text::Format" is perfect for this.  Could you post
   (or send) a link to a Mailman-generated HTML archive that has the
   problem you describe?  Then I can show a before-and-after along with a
   script that'll at least give you a starting point.

-- 
Karl Vogel  I don't speak for the USAF or my company

You know you're addicted to the Internet when your phone bill comes to
your door in a box.
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] Need to split long lines in mail archives

2012-04-10 Thread John Doe
From: James B. Byrne 

> What I would like to discover is the functional equivalent
> of this:
> find /path/to/archives/*.html -print | xargs -I {} fmt -s
> {} > {}
> This syntax does not work of course because the xargs file
> name substitution only occurs once in the initial argument
> list of the following command. But, this example does
> describe the effect I wish to obtain, to have the original
> file name receive the reformatted contents.

What about a simple:
find ... | while read F; do ... "$F"; done

JD
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos