Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #8 (permalink)  
Old 11-07-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,434
Doubling \ works fine :

Code:

$ echo '  c:\mydocuments\pictures ' | sed 's_c:\\mydocuments\\pictures_d:/mypics/personal_'
  d:/mypics/personal 
$

Jean-Pierre.
Sponsored Links
  #9 (permalink)  
Old 05-16-2008
Registered User
 

Join Date: May 2008
Posts: 2
script overwrites all the files in directory

Quote:
Originally Posted by aigles View Post
Doubling \ works fine :

Code:

$ echo '  c:\mydocuments\pictures ' | sed 's_c:\\mydocuments\\pictures_d:/mypics/personal_'
  d:/mypics/personal 
$

Jean-Pierre.
used the script above modified for my needs:

cd deploy
for y in `ls *.xml`;
do
sed 's_OLD.VALUE_NEW.VALUE_' $y > temp; mv temp $y;
done

works great except one thing: it overwrites all xml files changing their time stamp. is it possible to have the script updating only the ones that have OLD.VALUEs?
  #10 (permalink)  
Old 05-17-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Make the mv conditional.

Also lose the silly `ls *`


Code:

cd deploy
for y in *
do
  sed 's_OLD.VALUE_NEW.VALUE_' "$y" >temp
  if cmp temp "$y" >/dev/null
  then
    rm temp
  else
    mv temp "$y"
  fi
done

  #11 (permalink)  
Old 05-20-2008
Registered User
 

Join Date: May 2008
Posts: 2
Thank you era, works like a charm

Quote:
Originally Posted by era View Post
Make the mv conditional.

Also lose the silly `ls *`


Code:

cd deploy
for y in *
do
  sed 's_OLD.VALUE_NEW.VALUE_' "$y" >temp
  if cmp temp "$y" >/dev/null
  then
    rm temp
  else
    mv temp "$y"
  fi
done

  #12 (permalink)  
Old 01-15-2009
Registered User
 

Join Date: Jan 2009
Posts: 2
find and replace coding in perl

#!/usr/bin/perl
#bash#./ff.pl --prod \/opt\/ WebSphere5 --cob \/opt\/was6mig\/WebSphere5 -base

use File::Find;
use Getopt::Long;
#$dmPath="/scratch/optcob/cells.dmgr.tmp";
#Modify the Basepath with new copied WAS5 copied location.
$basePath="/opt/IBM/WAS6.1/IBMIHS/CI_CNV_CRD_HTTPServer";
$dmPath="/dm5"; # don't worry about this $basePath="/app/WebSphere6/profiles";
$tmpf="/tmp/tmpf";
sub ModFileByRegex {
my ($tok, $repl, $fpat, $Path) = (@_);
my $cnt = 0;
sub fwanted {
-f &&
$File::Find::name =~ /$fpat/ && do {
open (INF, $File::Find::name) || die "cannot open $File::Find::name : $!";
open (TMPF, ">$tmpf") || die "cannot open $tmpf for writing: $!";
my @input = <INF>;
my $change = grep { s/$tok/$repl/g } @input;
if ($change > 0) {
close INF;
print TMPF @input;
close TMPF;
print "updating/saving copy of $File::Find::name\n";
rename $File::Find::name, $File::Find::name . ".org";
print `cp -p $tmpf $File::Find::name\n`;
$cnt++;
}
}
}
print "searching from $Path for $tok in files called $fpat\n";
find (\&fwanted, $Path);
return ($cnt);
}
sub findDirByRegex {
my ($tok, $repl, $Path) = (@_);
my $cnt = 0;
sub wanted {
-d &&
$File::Find::name =~ /$tok[\w\.]*?$/ &&
push @DIRL, $File::Find::name;
}
print "Looking for directories from $Path called $tok\n";
find (\&wanted, $Path);
while ($_ = pop @DIRL) {
$src = $_;
s/$tok([\w\.]*)?$/$repl$1/;
print "rename $src, $_\n";
rename $src, $_ || warn "could not rename last file, please check";
$cnt++;
}
return ($cnt);
}
%optctl = ();
GetOptions (\%optctl, "prod=s", "cob=s", "dmgr", "base");
print "options set:\n\n";
print "prod system (source system) :" . $optctl{"prod"} . "\n";; print "cob system (target system) :" . $optctl{"cob"} . "\n"; print "Do Deployment Manager\n" if ($optctl{"dmgr"} == 1); print "Do Base WebSphere\n" if ($optctl{"base"} == 1);
print "\n\n";
if ($optctl{"dmgr"} == 1) {
print "updating Deployment Manager XML files\n";
$cnt = ModFileByRegex ($optctl{"prod"}, $optctl{"cob"}, ".*", $dmPath);
print "$cnt XML files were updated\n"; }
if ($optctl{"base"} == 1) {
print "updating WebSphere Base XML files\n";
$cnt = ModFileByRegex ($optctl{"prod"}, $optctl{"cob"}, ".*", $basePath);
print "$cnt XML files were updated\n"; }
if ($optctl{"dmgr"} == 1) {
print "updating Deployment Manager base Directory Names\n";
$cnt = findDirByRegex ($optctl{"prod"}, $optctl{"cob"}, $dmPath);
print "$cnt directory names updated\n"; }
if ($optctl{"base"} == 1) {
print "updating WebSphere base Directory Names\n";
$cnt = findDirByRegex ($optctl{"prod"}, $optctl{"cob"}, $basePath);
print "$cnt directory names updated\n"; }
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
find and replace string in a directory files koti_rama Shell Programming and Scripting 2 05-30-2008 04:48 AM
Find and replace a string in multiple files pharos467 UNIX for Dummies Questions & Answers 2 11-05-2007 11:47 PM
Find and Replace in multiple files (Shell script) jatins_s Shell Programming and Scripting 13 11-05-2007 02:11 PM
Find and replace files in multiple folders lodey Shell Programming and Scripting 6 09-28-2007 03:00 AM
find and FTP multiple files in Korn Shell lambjam UNIX for Dummies Questions & Answers 2 08-13-2007 11:50 PM



All times are GMT -4. The time now is 01:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0