Find and replace a string in several text files

Maybe you are looking for a particular phrase in log files or maybe you are a programmer and need to find some string that is inside many different code files?

Here is how you can find and replace a string in several text files.

For this example, the Oracle DBA wants to replace  strings NSR* in all rman scripts:

#!/usr/bin/ksh

for base in /oracle/scripts/rman/rcv/*.rcv
do
TMP=$(mktemp test.XXXXXX)
sed 's/NSR_SERVER=networker-hme0, NSR_DATA_VOLUME_POOL=BU UNT FULL/NSR_SERVER=freppax-laaf02h, NSR_DATA_VOLUME_POOL=FullHP/g' $base > "$TMP" && mv "$TMP" $base
done

export PS1="\$ORACLE_SID $LOGNAME@$(hostname):\${PWD}> "
stty erase ^H
export HISTSIZE=100
export EDITOR=vi
set -o vi
alias ll="ls -altr"
umask 022
Summary
Article Name
Find and replace a string in several text files
Description
Here is how you can find and replace a string in several text files. You need to find some string that is inside many different code files
Author
Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.