Ask a Question related to UNIX Programming, Design and Development.
-
Jens.Toerring@physik.fu-berlin.de #1
Re: Shell programming question...urgent help please!
Bob C. Little <bclasd@bellsouth.net> wrote:
> I need to write a shell program to break up a large file into multiple html
> files. The format of the large files is as follows: (what I need is
> file1.htm, file2.htm, file3.htm..etc.) Anyhelp will be greatly appreciated.Here's a Perl solution:> /path/to/where/the/files/needs/to/reside/file1.htm
> <html>
> blah, blah, blah
> blah, blah, blah
> </html>
> /path/to/where/the/files/needs/to/reside/file2.htm
> <html>
> blah, blah, blah
> blah, blah, blah
> </html>
> /path/to/where/the/files/needs/to/reside/file3.htm
> <html>
> blah, blah, blah
> blah, blah, blah
> </html>
------------------------8<--------------------------------------------
#!/usr/bin/perl -w
use strict;
my $if = *STDIN;
if ( $ARGV[ 0 ] ) {
open( $if, "<" . $ARGV[ 0 ] )
or die "Can't open input file $ARGV[ 0 ] : $!\n";
}
while ( my $path = <$if> ) {
chomp $path;
open( my $of, ">$path" ) or die "Can't open output file $path : $!\n";
while ( <$if> ) {
print $of $_;
last if /^\s*<\/html>\s*$/i;
}
close $of;
}
------------------------8<--------------------------------------------
Simply call it with the name of the input file as the argument
or with the input file redirected into the script.
Regards, Jens
--
_ _____ _____
| ||_ _||_ _| [email]Jens.Toerring@physik.fu-berlin.de[/email]
_ | | | | | |
| |_| | | | | | [url]http://www.physik.fu-berlin.de/~toerring[/url]
\___/ens|_|homs|_|oerring
Jens.Toerring@physik.fu-berlin.de Guest
-
freelance web programming, web site design,c programming, java programming, VERY Low Cost web design and more
Find expert freelance programmers and designers at the prices you want to pay. Post your projects and programmers will place bids, you choose the... -
Shell Programming
I am new to UNIX and I want to get a feel for shell scripting. I have seen examples and it looks complicated! I want to know is there a good book... -
Shell question.
Another shell question - $system is set to eq-cca-u1.etsd.ml.com , Running the commands below should give sysnew as eq-cca-u1 , stripping out the... -
Shell Programming: IFS variable
Hi all, I'm having a strange little problem that MUST have an answer but I can't seem to figure it out! I'm using a Bourne shell on SCO... -
A question on UDF programming
In a user-defined function, I have 31 variables each of which stores a "float" type value. The values stored in all these variables are supposedly... -
Jens.Toerring@physik.fu-berlin.de #2
Re: Shell programming question...urgent help please!
Dmitry Karasik <dmitry@karasik.eu.org> wrote:
> Hi Jens!> On 06 Aug 03 at 20:10, "Jens" (Jens Toerring) wrote:> Just for simplicity sake. The following five lines> Jens> my $if = *STDIN;
> Jens> if ( $ARGV[ 0 ] ) {
> Jens> open( $if, "<" . $ARGV[ 0 ] ) or die "Can't open input file $ARGV[ 0 ] : $!\n";
> Jens> }
> Jens> while ( my $path = <$if> )> are equivalent toNicely spotted. But then you also have to change the> while ( my $path = <>)
while ( <$if> ) {
appearing later to
while ( <> ) {
And you can also do without the 'chomp' line ;-)
Regards, Jens
--
_ _____ _____
| ||_ _||_ _| [email]Jens.Toerring@physik.fu-berlin.de[/email]
_ | | | | | |
| |_| | | | | | [url]http://www.physik.fu-berlin.de/~toerring[/url]
\___/ens|_|homs|_|oerring
Jens.Toerring@physik.fu-berlin.de Guest



Reply With Quote

