Last active
September 30, 2017 20:37
-
-
Save sokolenkoDEV/3887237a4baae0a3236f4391d9709ad0 to your computer and use it in GitHub Desktop.
Perl: replace in file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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