Jump to content

Recommended Posts

Posted

Срочно нужен скрипт для Линукс. который делает следующее: Есть html файл из него надо повырезать куски кода содержащиеся между словами <SCRIPT и SCRIPT>. Кусков может быть несколько надо все их вырезать включая сами <SCRIPT и SCRIPT>. Помогите пожалуйста или подскажите как это сделать. Может с помощью Sed или awk. или надо посимвольно проверять весь файл на совпадение со <SCRIPT?

Posted
#!/usr/bin/perl -w
# Синтаксис: script.pl <input_file>
open (INFILE, $ARGV[0]);
open (OUTFILE, ">>processed_" . $ARGV[0]);

my $read=1;
while (<INFILE>) {
  if (m/<script>/i) {
    $read=0;
  }
  if (m/<\/script>/i) {
    $read=1;
    next;
  }
  if ($read == 1) {
    print OUTFILE $_;
  }
}
close OUTFILE;
close INFILE;

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...