remove some tags in multiple files

Discussion in 'HTML' started by Tomba, Oct 14, 2003.

  1. Tomba

    Tomba Guest

    hello all,

    I'm not sure if this would be the appropriate groupd, but it concerns html
    files.
    In fact I have a folder filled with html files, and I would like to remove
    all from <head> to </head> in each file of that folder.

    Does anyone know what would be the most convenient way to do this?
    thanks in advance,

    Steven De Groote

    --
    Webmaster of:
    http://www.f1technical.net/
    http://formule1.go2.be/
    Tomba, Oct 14, 2003
    #1
    1. Advertising

  2. Tomba wrote:

    > In fact I have a folder filled with html files, and I would like to remove
    > all from <head> to </head> in each file of that folder.


    Not sure why you'd want to do that, but try this Perl script:

    use strict;
    use warnings;

    my $foldername = shift @ARGV or die("can't get folder name\n");
    opendir(FOLDER, $foldername) or die("can't open $foldername: $!\n");
    chdir($foldername) or die("can't change directory to $foldername: $!");
    while (my $filename = readdir(FOLDER)) {
    next unless ($filename =~ /\.html?$/i);
    print "removing head of $filename\n";
    open(FILE, $filename) or warn("can't open $filename for reading: $!\n");
    my $file;
    while (my $filepart = <FILE>) {
    $file .= $filepart;
    }
    close FILE or warn("can't close $filename: $!\n");
    $file =~ s#<head((?: [^>]*)?)>.*</head>#<head$1></head>#si;
    open(FILE, ">$filename") or warn("can't open $filename for writing: $!\n");
    print FILE $file;
    close FILE or warn("can't close $filename: $!\n");
    }
    closedir FOLDER or die("can't close $foldername: $!\n");
    Leif K-Brooks, Oct 14, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dean H. Saxe
    Replies:
    0
    Views:
    1,023
    Dean H. Saxe
    Jan 3, 2004
  2. Rob Nicholson
    Replies:
    3
    Views:
    715
    Rob Nicholson
    May 28, 2005
  3. Spondishy
    Replies:
    3
    Views:
    838
    Spondishy
    Jan 4, 2006
  4. Replies:
    4
    Views:
    949
    M.E.Farmer
    Feb 13, 2005
  5. dwelden
    Replies:
    11
    Views:
    480
    Neil Cerutti
    Jan 4, 2007
Loading...

Share This Page