Shell programming question...urgent help please!

Ask a Question related to UNIX Programming, Design and Development.

  1. #1

    Default 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.
    > /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>
    Here's a Perl solution:

    ------------------------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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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...
    5. 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...
  3. #2

    Default 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 to
    > while ( my $path = <>)
    Nicely spotted. But then you also have to change the

    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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139