Skip to content

Instantly share code, notes, and snippets.

@sokolenkoDEV
Last active September 30, 2017 20:37
Show Gist options
  • Save sokolenkoDEV/3887237a4baae0a3236f4391d9709ad0 to your computer and use it in GitHub Desktop.
Save sokolenkoDEV/3887237a4baae0a3236f4391d9709ad0 to your computer and use it in GitHub Desktop.
Perl: replace in file
# change plugin in wordpress Auto SyntaxHighlighter -> Enlighter - Customizable Syntax Highlighter
# dump site database to mybash-2017-30-09.sql
# write script to replace
<pre class=\"brush:php\">
<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">
#!/usr/bin/perl
use warnings;
use strict;
use feature 'say';
my $file = './public_html/mybash-2017-30-09.sql';
open ( my $fh, '<', $file) or die "can't open $file - $!";
my @list = ();
while (<$fh>)
{
$_ =~ s/<pre class=\\"brush:\s?(\w*)\\">/<pre class=\\"EnlighterJSRAW\\" data-enlighter-language=\\"$1\\">/g;
push (@list, $_);
}
close $fh;
open ($fh, '>', $file) or die "can't open $file - $!";
print $fh @list;
close $fh;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment