Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Restoring a user’s original password 1051962.101 Oracle
  • GSQ.sql Oracle
  • oracle 11g RAC on vmware Oracle
  • fkwoindex.sql /* Find FK without Index */ Oracle
  • V$CONTROLFILE_RECORD_SECTION reference notes. Oracle
  • v$event_name Oracle
  • Follwoing korn shell is used to move files from source folder to destination folder and gzip it in destination folder. mv_iotto.ksh Linux/Unix
  • login.sql Oracle
  • newupload.html PHP/MYSQL/Wordpress
  • Remove duplicate rows from table Oracle
  • PHP code to add WordPress posts in bulk programmatically PHP/MYSQL/Wordpress
  • On solaris 10, “S” link is not part of $ORACLE_HOME/bin/oracle as default. ( For 9.2.0.8) Oracle
  • Passing from Unix to PLSQL using bind variables Linux/Unix
  • load SPM baseline from cursor cache Oracle
  • When to rebuld B-tree index Oracle

Search and replace pattern

Posted on 07-Nov-2007 By Admin No Comments on Search and replace pattern

#!/bin/ksh

file_name=$1

old_templet=$2

new_templet=$3

# Loop through every file like this

for file in file_name

do

cat $file | sed “s/old_templet/new_templet/g” > $file.new

#do a global searce and replace and put the results

mv $file.new $file

#rename $file.new to original name of file

done

If you want to replace single pattern with a new pattern witn newline use following:

modify the sed part to

sed ‘s/old_template/new_templ1^Jnew_templ2^Jnew_templ3/’ tst

here the ^J

is then a ctrl-V and hit the return key, u ll c a ^J character

besides instead of doing the cat and redirecting to one file and then moving the new file to old u can do

perl -i -ne “s/old_template/new_templ1nnew_templ2nnew_templ3/” file1

file1 will be overwritten with the desired result , use the n instead of ^J in perl

Linux/Unix, shell

Post navigation

Previous Post: create a folder in multiple places
Next Post: adding new line after specific pattern using sed

Related Posts

  • move_arch_files.ksh /* Good One */ Linux/Unix
  • move_arch_files.ksh Linux/Unix
  • How does one SELECT a value from a table into a Unix variable? From SQL to Shell Linux/Unix
  • rm_backup_arch_file.ksh Linux/Unix
  • Removing Ctrl-M from end of line using vi Linux/Unix
  • Check_recovery.sh program to run sqlplus and return its values remotely. Linux/Unix

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • AWS (2)
  • Azure (1)
  • Linux/Unix (149)
  • Oracle (392)
  • PHP/MYSQL/Wordpress (10)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (341)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • load SPM baseline from cursor cache05-Jun-2025
  • Drop all SPM baselines for SQL handle05-Jun-2025
  • Load SPM baseline from AWR05-Jun-2025
  • Drop specific SQL plan baseline – spm05-Jun-2025
  • findinfo.sql (SQL for getting CPU and Active session info)27-May-2025
  • SQL Tracker by SID sqltrackerbysid.sql22-Apr-2025
  • How to connect to Oracle Database with Wallet with Python.21-Mar-2025
  • JSON/XML Types in Oracle18-Mar-2025
  • CPU Core related projections12-Mar-2025
  • Exadata Basics10-Dec-2024

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • dbms_job.submit example Oracle
  • Load SPM baseline from AWR Oracle
  • to see when crontab is changed. Linux/Unix
  • How to find where datafile is created dbf_info.sql Oracle
  • move_arch_files.ksh /* Good One */ Linux/Unix
  • USER_TABLES.Freelists Oracle
  • Load testing on Oracle 19C RAC with HammerDB Oracle
  • Reclaim temp tablespace for oracle 8, 8i Oracle

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme