ALT Linux Community general discussions
 help / color / mirror / Atom feed
From: "Дорогов Николай" <support@planetashop.ru>
To: <community@altlinux.ru>
Subject: Re: [Comm] Re: [JT] Поиск и замена
Date: Wed, 20 Apr 2005 17:56:43 +0400
Message-ID: <005801c545b0$c8e3f370$0200a8c0@admin> (raw)
In-Reply-To: <20050420132829.GR9438@wrars-comp.wrarsdomain>

Проблему поиска и замены текста в файлах с именами по маске
на половину решил следующим скриптом,
который нашел на сайте http://www.vanta.ru/script/info.php?id=498&clas=2
Не хватает прохода по вложенным папкам. А так просто сказочный скриптик.

#!/usr/bin/perl

 #  ====================================================================
 #  Copyright (c) 1998-2000 Marcus Kazmierczak, marcus@mkaz.com
 #  All rights reserved.
 #
 #  Redistribution and use in source and binary forms, with or without
 #  modification, are permitted provided that the following conditions
 #  are met:
 #
 #  1. Redistributions of source code must retain the above copyright
 #     notice, this list of conditions and the following disclaimer.
 #
 #  2. Redistributions in binary form must reproduce the above copyright
 #     notice, this list of conditions and the following disclaimer in the
 #     documentation and/or other materials provided with the distribution.
 #
 #  3. The name of the author may not be used to endorse or promote products
 #     derived from this software without specific prior written permission.
 #
 #  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 #  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES
 #  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 #  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 #  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 #  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE,
 #  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 #  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 #  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 #  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #  ====================================================================
 #

#
#   APP: mksr
#   ORIGIN: August 1999
#
#   VERSION NUMBER
$ver = "ver 0.0.5";

#   Last Modified: November 2000
#
#   Auth: Marcus Kazmierczak
#         marcus@mkaz.com
#         http://blazonry.com/perl/
#
#   DESC: Search and Replace
#

print "\nmksr Search and Replace    $ver\n";
print "Marcus Kazmierczak, marcus\@mkaz.com\n\n";

# TODO LIST
#
# - ADD Recursion Option

    ## REQUIRED CPAN MODULES ##
    # File::Recurse Module bundled with File-Tools 2.0
    # download from CPAN site
(http://www.perl.com/CPAN//modules/by-module/File/)
    # use File::Recurse;
    ####


my $find = $ARGV[0];
my $replace = $ARGV[1];
my $glob = $ARGV[2];

@filelist = <*$glob>;

if ( (!$find) || (!$replace) || (!$glob) ) {
    print "Search and replace recursively through the current directory\n";
    print "replacing <find> with <replace> in each file specified.\n";
    print "To use wildcards leave off the * Ex: '.txt' \n\n";
    print "    mksr <find> <replace> <file>\n";

    exit(0);
}


# process each file in file list
foreach $filename (@filelist) {

    print "    P: $filename\n";

    # retrieve complete file
    open (IN, "$filename") || die("Error Reading File: $filename $!");
    {
        undef $/;
        $infile = <IN>;
    }
    close (IN) || die("Error Closing File: $filename $!");

    $infile =~ s/$find/$replace/g;


    # write complete file
     open (PROD, ">$filename") || die("Error Writing to File: $filename
$!");
     print PROD $infile;
     close (PROD) || die("Error Closing File: $filename $!");

}

   print "\nFinished.\n";


   exit(0);


----- Original Message ----- 
From: "Andrey Rahmatullin" <wrar@altlinux.ru>
To: <community@altlinux.ru>
Sent: Wednesday, April 20, 2005 5:28 PM
Subject: Re: [Comm] Re: [JT] Поиск и замена


> _______________________________________________
> Community mailing list
> Community@altlinux.ru
> https://lists.altlinux.ru/mailman/listinfo/community



  reply	other threads:[~2005-04-20 13:56 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-19 12:20 ` [Comm] " Eugene A. Suchkov
2005-04-19 12:32 ` Alexey Rusakov
2005-04-19 12:51   ` Дорогов Николай
2005-04-19 12:52     ` Alexey Rusakov
2005-04-19 13:08       ` [Comm] [JT] " Michael Isachenkov
2005-04-19 13:12         ` Re[2]: " Anton Gorlov
2005-04-19 13:18           ` Michael Isachenkov
2005-04-19 13:13         ` Olvin
2005-04-19 13:21         ` Alexey Rusakov
2005-04-19 14:02           ` Michael Isachenkov
2005-04-19 14:53         ` [Comm] " Michael Shigorin
2005-04-19 16:45           ` Michael Isachenkov
2005-04-19 17:06             ` Michael Shigorin
2005-04-19 17:10               ` Michael Isachenkov
2005-04-19 21:32               ` Olvin
2005-04-20 12:09                 ` Michael Shigorin
2005-04-20 13:28           ` Andrey Rahmatullin
2005-04-20 13:56             ` Дорогов Николай [this message]
2005-04-19 12:55     ` [Comm] " Nick S. Grechukh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='005801c545b0$c8e3f370$0200a8c0@admin' \
    --to=support@planetashop.ru \
    --cc=community@altlinux.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Community general discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git