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

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

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,227
    Dean H. Saxe
    Jan 3, 2004
  2. Rob Nicholson
    Replies:
    3
    Views:
    1,011
    Rob Nicholson
    May 28, 2005
  3. Spondishy
    Replies:
    3
    Views:
    933
    Spondishy
    Jan 4, 2006
  4. Ranganath

    Custom Tags within Custom Tags.

    Ranganath, Oct 17, 2003, in forum: Java
    Replies:
    2
    Views:
    638
    Ranganath
    Oct 21, 2003
  5. Mike
    Replies:
    3
    Views:
    1,226
    Michael Borgwardt
    Jan 9, 2004
  6. Replies:
    4
    Views:
    1,216
    M.E.Farmer
    Feb 13, 2005
  7. dwelden
    Replies:
    11
    Views:
    590
    Neil Cerutti
    Jan 4, 2007
  8. MM User

    Spaces in some files some not

    MM User, Dec 11, 2008, in forum: ASP General
    Replies:
    3
    Views:
    175
    Adrienne Boswell
    Dec 13, 2008
Loading...