Saturday, March 5, 2011
Replace string in multiple files
$ find -E ./ -iregex '.*menu_.*\.(cpp|h)$' | xargs sed -E -i~ 's/ORG/NEW/g'
Multiple file name change
$ find -E ./ -iregex '.*menu_.*\.(cpp|h)$' > file.list
$ perl -w rename.pl file.list
-----------------------------------------
while($line = <>) {
if($line =~ m/.*(\bMenu_Setting.*)/i) {
# print "$1\n";
$old = $line;
$old =~ s/^\./\/home\/max\/src\/csu502 can\/acu-stm32-lcd/;
$old =~ s/\n//;
print "$old\n";
$newname = $old;
# replace file name
$newname =~ s/Menu_Setting_//;
print "$newname\n\n";
# use shell command: mv
system("mv", "$old", "$newname");
}
}
Subscribe to:
Posts (Atom)