Thread View: comp.unix.shell
3 messages
3 total messages
Started by Bill Poitras
Wed, 10 Oct 1990 13:55
Parsing a news article with source in it
Author: Bill Poitras
Date: Wed, 10 Oct 1990 13:55
Date: Wed, 10 Oct 1990 13:55
17 lines
1390 bytes
1390 bytes
What I am trying to do is pipe a news article through a shell script
(preferable /bin/sh) so that it parses the header, extracts the filename
from the "Archive: ..." line, and then writes the rest of the file,
from the '!# /bin/sh' line to the end to filename specified in the
"Archive: ..." line. I can't seem to get the shell script to read up to
the !# /bin/sh using <<. There are basically two tasks:
1) Parsing the header, extracting the filename in the Archive line
2) Writing the rest of the file to the filename gotten from #1
Does such a script exist? Any help would greatly be appreciated.
+-----------------+---------------------------+-----------------------------+
| Bill Poitras | Polygen Corporation | {princeton mit-eddie |
| (bill) | Waltham, MA USA | bu sunne}!polygen!bill |
| | | bill@polygen.com |
+-----------------+---------------------------+-----------------------------+
Re: Parsing a news article with source in it
Author: Tom Christiansen
Date: Fri, 12 Oct 1990 13:42
Date: Fri, 12 Oct 1990 13:42
29 lines
1631 bytes
1631 bytes
In article <838@redford.UUCP> bill@redford.UUCP (Bill Poitras(X258)) writes:
>What I am trying to do is pipe a news article through a shell script
>(preferable /bin/sh) so that it parses the header, extracts the filename
>from the "Archive: ..." line, and then writes the rest of the file,
>from the '!# /bin/sh' line to the end to filename specified in the
>"Archive: ..." line. I can't seem to get the shell script to read up to
>the !# /bin/sh using <<. There are basically two tasks:
> 1) Parsing the header, extracting the filename in the Archive line
> 2) Writing the rest of the file to the filename gotten from #1
>Does such a script exist? Any help would greatly be appreciated.
It does now. :-)
#!/usr/bin/perl -n
if (1 .. /^$/) {
die "can't write to $1: $!" if /^Archive:\s*(\S+)/ && !open(STDOUT, ">$1");
} elsif (/^!#\s*\/bin\/sh/ .. eof) {
print;
}
I'd actually feel more confortable if I had some sample input, but
I believe this matches your spec.
--tom
--
"UNIX was never designed to keep people from doing stupid things, because
that policy would also keep them from doing clever things." [Doug Gwyn]
Re: Parsing a news article with source in it
Author: Edward Vielmetti
Date: Sat, 13 Oct 1990 03:58
Date: Sat, 13 Oct 1990 03:58
24 lines
1748 bytes
1748 bytes
In article <107116@convex.convex.com> tchrist@convex.COM (Tom Christiansen) writes: In article <838@redford.UUCP> bill@redford.UUCP (Bill Poitras(X258)) writes: >What I am trying to do is pipe a news article through a shell script >(preferable /bin/sh) so that it parses the header, extracts the filename >from the "Archive: ..." line, and then writes the rest of the file, I'd actually feel more confortable if I had some sample input, but I believe this matches your spec. Try comp.archives or comp.unix.sources as a sample spec, go for the Archive-name: header. Make sure you create whatever directories are necessary along the way. there's a program "rkive" from comp.sources.misc which does this as well, and a few others of their ilk, but to my knowlege nothing in perl (yet). It appears that to do it right and bullet-proof enough for automated execution is non-trivial, that is to say not intrinsically hard but a lot of potential error conditions which would need to be dealt with sensibly. --Ed Edward Vielmetti, U of Michigan math dept <emv@math.lsa.umich.edu> moderator, comp.archives
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads