青草久久影院-青草久久伊人-青草久久久-青草久久精品亚洲综合专区-SM双性精跪趴灌憋尿调教H-SM脚奴调教丨踩踏贱奴

17站長網(wǎng)

17站長網(wǎng) 首頁 腳本 perl 查看內(nèi)容

Perl腳本batchReplace.pl用來批量替換文字/代碼工具詳解

2022-12-5 09:16| 查看: 2488 |來源: 互聯(lián)網(wǎng)

下面給大家介紹的Perl腳本batchReplace.pl用來批量替換文字/代碼工具詳解,你可能還不知道,下面我門一起來看看,希望對需要的朋友有所幫助!Perl腳本batchReplace.pl可以用來批量替換文件中的文字/代碼。可在指定目

下面給大家介紹的Perl腳本batchReplace.pl用來批量替換文字/代碼工具詳解,你可能還不知道,下面我門一起來看看,希望對需要的朋友有所幫助!

Perl腳本batchReplace.pl可以用來批量替換文件中的文字/代碼。可在指定目錄中查找指定類型的文件,并遞歸檢查子目錄;在輸出文件時(shí)復(fù)制輸入文件的目錄結(jié)構(gòu)。


[附件]Win32應(yīng)用程序batchReplace.exe是由Perl腳本編譯產(chǎn)生的可執(zhí)行程序,不需安裝Perl運(yùn)行環(huán)境即可執(zhí)行。


在命令行中使用

batchReplace.exe[ -i 輸入文件路徑(或包含文件的目錄)][ -o 輸出文件位置(文件或目錄)][ -c 批量輸入文件的擴(kuò)展名,以“.”開始,多個(gè)擴(kuò)展名之間以“|”隔開][ -m 匹配模式][ -I(忽略匹配內(nèi)容的字母大小寫)][ -G(全局查找要匹配的內(nèi)容)][ -e 例外的字符串,是對匹配模式的補(bǔ)充,如果在匹配結(jié)果中發(fā)現(xiàn)有這樣的字符串,做不匹配處理][ -r 替換的內(nèi)容]

上述參數(shù)沒有順序限制。當(dāng) -o 參數(shù)所涉及的文件路徑不存在時(shí),會自動創(chuàng)建。當(dāng)輸出文件已經(jīng)存在時(shí),文件原有的內(nèi)容將被覆蓋。(安全起見,請不要輸出到輸入文件的原始位置,以免造成不可恢復(fù)的損失。)

例如:
batchReplace.exe -i d:\gaoshu1 -o d:\do\123\456 -e http://www.blueidea.com/


通過配置文件 batchReplace.set 設(shè)置參數(shù)

配置文件中可包含以下設(shè)置項(xiàng)目(格式范例,注意大小寫):


Input=E:\fna\                 指定輸入路徑,相當(dāng)于命令行參數(shù) -i 的默認(rèn)值。
-i=E:\fna\                    同上。
Output=E:\dnaWalks\           指定輸出路徑,相當(dāng)于命令行參數(shù) -o 的默認(rèn)值。
-o=E:\dnaWalks\               同上。
Match=]*>[\s\S]*?<\/iframe>  匹配模式,相當(dāng)于命令行參數(shù) -m 的默認(rèn)值。
-m=]*>[\s\S]*?<\/iframe>  同上。
Insensitive                   忽略匹配內(nèi)容的字母大小寫,相當(dāng)于命令行參數(shù) -I。
-I                            同上。
Global                        全局查找要匹配的內(nèi)容,相當(dāng)于命令行參數(shù) -G。
-G                            同上。
Replacement=

bound0

   替換的內(nèi)容,相當(dāng)于命令行參數(shù) -r 的默認(rèn)值。
-r=

bound0

            同上。
Except=http://www.blueidea.com/ 例外的字符串,如在匹配結(jié)果中發(fā)現(xiàn)有這樣的字符串,做不匹配處理,相當(dāng)于命令行參數(shù) -e 的默認(rèn)值。
-e=http://www.blueidea.com/   同上。
CheckType=.htm|.html          當(dāng)輸入?yún)?shù)設(shè)為目錄時(shí),處理目錄中包含的具有這些擴(kuò)展名的文本文件(遞歸檢查子目錄)。相當(dāng)于命令行參數(shù) -c 的默認(rèn)值。
-c                            同上。

每行放置一個(gè)項(xiàng)目。除內(nèi)容之間不要有多余的空格或引號。 
除必要的輸入輸出外,所有的設(shè)置項(xiàng)目都是可選的。命令行參數(shù)會覆蓋相應(yīng)的默認(rèn)值。如果在配置文件中不包含Match或CheckType,會啟用內(nèi)置的默認(rèn)值(同上面示例中給出的值)。Replacement默認(rèn)為空字符,將匹配內(nèi)容替換為空字符,也就是將匹配內(nèi)容清除。

欲在batchReplace.set中保留歷史配置時(shí),可在參數(shù)前放置任意非空白字符以取消其作用。
例如:
2007/04/06 Insensitive
(此處的 Insensitive 將作為歷史配置保留,不再生效。)

2007/04/06 Replacement=

bound0


(此處的 Replacement=

bound0

 將作為歷史配置保留,不再生效。)

如果在配置文件的多行中出現(xiàn)同樣的項(xiàng)目,以最后出現(xiàn)的設(shè)置為準(zhǔn),例如:
CheckType=.htm|.html
CheckType=.jsp
-c=.asp|.php
將設(shè)置CheckType的值為.asp|.php,也可以利用這個(gè)特性保留歷史配置,方便調(diào)試。


這個(gè)腳本寫得比較倉促(是擠出吃晚飯的時(shí)間寫的),以后有時(shí)間我還會改進(jìn)。(因此轉(zhuǎn)載請注明出處,并注意更新。)


[免責(zé)聲明]作者不承擔(dān)用戶因使用此工具而造成的任何意外損失。
perl源碼

#file:batchReplace.pl
#author:Bound0
#created:2007-04-06
#first published: http://bbs.blueidea.com/viewthread.php?tid=2734388

my $match;
my $replacement='';
my $insensitive=0;
my $global=0;
my $gi;
my $go;
my $Checktype=".htm|.html";
my $except;

if(open(setfile,"{
    while()
    {
        if(/^\s*-I/){$insensitive=1}
        if(/^\s*-G/){$global=1}
        if(/^\s*-m=(.+)/){$match=$1}
        if(/^\s*-r=(.+)/){$replacement=$1}
        if(/^\s*-e=(.+)/){$except=$1}
        if(/^\s*-i=(.+)/){$gi=$1}
        if(/^\s*-o=(.+)/){$go=$1}
        if(/^\s*-c=(.+)/){$Checktype=$1}
        if(/^\s*Insensitive/){$insensitive=1}
        if(/^\s*Global/){$global=1}
        if(/^\s*Match=(.+)/){$match=$1}
        if(/^\s*Replacement=(.+)/){$replacement=$1}
        if(/^\s*Except=(.+)/){$except=$1}
        if(/^\s*Input=(.+)/){$gi=$1}
        if(/^\s*Output=(.+)/){$go=$1}
        if(/^\s*CheckType=(.+)/){$Checktype=$1}
    }
}

my $para=' '.join(' ',@ARGV);
if($para=~/ -I */){$insensitive=1}
if($para=~/ -G */){$global=1}
my @ti=split(/ -i */,$para);
if($ti[1]){($gi)=split(/ -(o|i|c|e|m|r|I|G)/,$ti[1])}
unless($gi){print "No \"Input path\" parameter!";exit}
my @to=split(/ -o */,$para);
if($to[1]){($go)=split(/ -(o|i|c|e|m|r|I|G)/,$to[1])}
unless($go){print "No \"Output path\" parameter!";exit}
my @tc=split(/ -c */,$para);
if($tc[1]){($Checktype)=split(/ -(o|i|c|e|m|r|I|G)/,$tc[1])}
my @te=split(/ -e */,$para);
if($te[1]){($except)=split(/ -(o|i|c|e|m|r|I|G)/,$te[1])}
my @tr=split(/ -r */,$para);
if($tr[1]){($replacement)=split(/ -(o|i|c|e|m|r|I|G)/,$tr[1])}

unless($match){$match="]*>[\\s\\S]*?<\\/iframe>";
$insensitive=1;
$global=1}

my @tm=split(/ -m */,$para);
if($tm[1]){($match)=split(/ -(o|i|c|e|m|r|I|G)/,$tm[1])}
unless($match){print "No \"Match Pattern\" parameter!";exit}

my $checktyp='(';
$Checktype=~s/\./\\\./g;
$Checktype=~s/\|/\)\|\(/g;
$checktyp.=$Checktype.')$';

my $excep;
if($except){
$excep=$except;
$excep=~s/\//\\\//g;
$excep=~s/\./\\\./g;
$excep=~s/\|/\\\|/g;
$excep=~s/\[/\\\[/g;
$excep=~s/\]/\\\]/g;
$excep=~s/\(/\\\(/g;
$excep=~s/\)/\\\)/g;
$excep=~s/\$/\\\$/g;
$excep=~s/\?/\\\?/g;
}

my $replacemen;
if($replacement){
$replacemen=$replacement;
$replacemen=~s/\//\\\//g;
$replacemen=~s/\./\\\./g;
$replacemen=~s/\|/\\\|/g;
$replacemen=~s/\[/\\\[/g;
$replacemen=~s/\]/\\\]/g;
$replacemen=~s/\(/\\\(/g;
$replacemen=~s/\)/\\\)/g;
$replacemen=~s/\$/\\\$/g;
$replacemen=~s/\?/\\\?/g;
}

sub cFile
{
    my $fi;
    ($fi)=@_;
    if(opendir(DIR, $fi))
    {
        my @dir=readdir(DIR);
        closedir DIR;
        if("\\" eq substr $fi,(length $fi)-1){$fi=substr($fi,0,(length $fi)-1)}
        my @subdirs= grep { /^(?!\.)/ && -d "$fi\\$_" } @dir;
        foreach my $subdir (@subdirs)
        {
            cFile("$fi\\$subdir")
        }
        @files = grep { /$checktyp/i  && -T "$fi\\$_" } @dir;
        foreach my $fil (@files)
        {
            my $bp='';
            $bp=(substr $fi,(length $gi))."\\";
            my $bi="$fi\\$fil";
            my $bo=$go.$bp.$fil;
            remove($bi,$bo)
        }
    }
}
unless("\\" eq substr $go,(length $go)-1){$go.="\\"}
if(-d $gi)
{
    unless("\\" eq substr $gi,(length $gi)-1){$gi.="\\"}
    cFile($gi);
}
else
{
    my $bu=substr $gi,(rindex $gi,'\\');
    my $bo=$go.$bu;
    remove($gi,$bo)
}

print "\nProcess Finished!";
print "\n-i:$gi";
print "\n-o:$go";
print "\n-m:$match";
if($except){print "\n-e:$except"}
if($replacement){print "\n-r:$replacement"}
sub remove
{
    my $bi;
    my $bo;
    ($bi,$bo)=@_;

    print "\nprocessing $bi ...\n";
    unless(open(INPUT,"<$bi")){print "\n[Warn] Can not open the file <$bi>: $!";return}
    my @conts = ;
    close INPUT;
    my $cont=join '',@conts;
    my $c;
    if($insensitive)
    {
        if($global)
        {
            unless($cont=~s/($match)/${$c=Cexcept($1)}$c/gi){die "$!"}
        }
        else
        {
            unless($cont=~s/($match)/${$c=Cexcept($1)}$c/i){die "$!"}
        }
    }
    else
    {
        if($global)
        {
            unless($cont=~s/($match)/${$c=Cexcept($1)}$c/g){die "$!"}
        }
        else
        {
            unless($cont=~s/($match)/${$c=Cexcept($1)}$c/){die "$!"}
        }
    }
    unless(open(OUT, ">$bo"))
    {
        if($!==2)
        {
            my $dbo=substr $bo,0,(rindex $bo,'\\');
            if(opendir(OUTDIR,$dbo)){closedir OUTDIR;print "\n[Warn] Can not open the output file <$bo>: $!";exit}
            else
            {
                if($!==2)
                {
                    unless(pmkpath($dbo)){print "\n[Warn] Can not creat the output directory <$dbo>: $!";exit}
                    unless(open(OUT,">>$bo")){print "\n[Warn] Can not open the output file <$bo>: $!";exit}
                }
                else{print "\n[Warn] Can not open the output directory <$dbo>: $!";exit}
            }
        }
        else{print "\n[Warn] Can not open the output file <$bo>: $!";exit}
    }

    print OUT "$cont";
    close OUT;
}
sub pmkpath
{
    my @p=split(/\\/,shift);
    my $pa=$p[0];
    my $m=$#p+1;
    my $t;
    for($t=1; -e $pa;$t++){$pa.='\\'.$p[$t]}
    unless(mkdir $pa){return 0}
    for(;$t<$m;$t++)
    {
        $pa.='\\'.$p[$t];
        unless(mkdir $pa){return 0}
    }
    return 1
}
sub Cexcept
{
    unless($except){return $replacemen}
    my $con;
    ($con)=@_;
    if($con=~/$excep/){return $con}else{return $replacemen}    
}


打包的exe文件下載

以上Perl腳本batchReplace.pl用來批量替換文字/代碼工具詳解就是小編為大家收集整理的全部內(nèi)容了,希望對大家有所幫助。如果您喜歡這篇文章,可以收藏或分享給您的小伙伴們吧!歡迎持續(xù)關(guān)注我們的后續(xù)更新。

本文最后更新于 2022-12-5 09:16,某些文章具有時(shí)效性,若有錯(cuò)誤或已失效,請?jiān)诰W(wǎng)站留言或聯(lián)系站長:[email protected]
·END·
站長網(wǎng)微信號:w17tui,關(guān)注站長、創(chuàng)業(yè)、關(guān)注互聯(lián)網(wǎng)人 - 互聯(lián)網(wǎng)創(chuàng)業(yè)者營銷服務(wù)中心

免責(zé)聲明:本站部分文章和圖片均來自用戶投稿和網(wǎng)絡(luò)收集,旨在傳播知識,文章和圖片版權(quán)歸原作者及原出處所有,僅供學(xué)習(xí)與參考,請勿用于商業(yè)用途,如果損害了您的權(quán)利,請聯(lián)系我們及時(shí)修正或刪除。謝謝!

17站長網(wǎng)微信二維碼

始終以前瞻性的眼光聚焦站長、創(chuàng)業(yè)、互聯(lián)網(wǎng)等領(lǐng)域,為您提供最新最全的互聯(lián)網(wǎng)資訊,幫助站長轉(zhuǎn)型升級,為互聯(lián)網(wǎng)創(chuàng)業(yè)者提供更加優(yōu)質(zhì)的創(chuàng)業(yè)信息和品牌營銷服務(wù),與站長一起進(jìn)步!讓互聯(lián)網(wǎng)創(chuàng)業(yè)者不再孤獨(dú)!

掃一掃,關(guān)注站長網(wǎng)微信

大家都在看

    熱門排行

      最近更新

        返回頂部
        主站蜘蛛池模板: YELLOW日本动漫高清免费 | 亚洲国产第一 | 久久视频精品38在线播放 | 亚洲成 人a影院青久在线观看 | 古月娜下面好紧好爽 | 久久学生精品国产自在拍 | 亚洲一区二区免费看 | 超碰在线97av视频免费 | 99久久夜色精品国产亚洲AV卜 | 西施打开双腿下面好紧 | 久久黄色片| 秋霞网在线伦理免费 | 777琪琪午夜理论电影网 | 十九岁韩国电影在线观看 | 牛牛自拍国产免费视频 | 日韩AV片无码一区二区三区不卡 | 草草久久久无码国产专区全集观看 | 男女夜晚在爽视频免费观看 | 人禽l交视频在线播放 视频 | 色悠久久综合 | HEYZO无码中文字幕人妻 | 中文字幕欧美一区 | 男女高潮又爽又黄又无遮挡 | 久久性色AV亚洲电影无码 | 影音先锋av丝袜天堂 | 国产成人精品系列在线观看 | 日本夜爽爽一区二区三区 | 被老总按在办公桌吸奶头 | 久久九九精品国产自在现线拍 | 国产黄A片在线观看永久免费麻豆 | 日本 一二三 不卡 免费 | 青青久久精品 | 国产人成高清在线视频99 | avtt天堂网2014| 国语精彩对白2021 | 色屁屁影院| 在线va无卡无码高清 | 国产在线公开视频 | 宝贝你骚死哥了好爽 | 新图解av吧 | 黄色a三级三级三级免费看 黄色a三级免费看 |