Posted on 2008/09/08 13:03
Filed Under [1] IT 관련/2. Linux

출처는 channel.net의 산이형 홈페이지에서 퍼왔습니다.

#! /usr/bin/perl -w
# PERL Scripted by bando
# DATE : 20040805
# Mail : bando(0x40)bando.org
# MSN : bando(0x40)bando.org
# 특정 경로이하 또는 파일에서 특정 문자열을 원하는 문자열로 변경하는 펄 스크립트

if ( $#ARGV != 2 ) {
  &Usage();
}

$Chan_path = $ARGV[0];
$Chan_ch = $ARGV[1];
$Chand_ch = $ARGV[2];
$total = 0;

if ( ! -e $Chan_path) {
  print "$Chan_path 와 같은 파일이나 디렉토리는 없습니다!\n";
  exit 1;
}

@arry = `grep "$Chan_ch" -l -r $Chan_path`;
foreach(0..$#arry) {
  $arry[$_] =~ s/\&/\\&/g;
  $arry[$_] =~ s/\(/\\(/g;
  $arry[$_] =~ s/\)/\\)/g;
  chomp($arry[$_]);
  `perl -p -i -e 's/$Chan_ch/$Chand_ch/g' $arry[$_]`;
  print "$arry[$_] : $Chan_ch => $Chand_ch [OK]\n";
  $total++;
}

print "\nTOTAL : $total 개 변경됨!\n\n";
sub Usage {
print   "\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n";
print "사용법 : $0 [이 경로이하 또는 파일에서] [이 문자열을] [이 문자열로 변경]\n\n";
print "설명 : 일치하는 문자열을 특정 문자열로 변경한다.\n";
print "예제 : $0 /home localhost 127.0.0.1\n";
print "결과 : /home 디렉토리 이하의 모든 파일에서 localhost문자열을 127.0.0.1문자열로 변경한다.\n";
print "\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n";
exit;
}

2008/09/08 13:03 2008/09/08 13:03

트랙백 주소 : http://jaehun.org/trackback/24

About

by Jaehun

Counter

· Total
: 51167
· Today
: 18
· Yesterday
: 100