Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Oracle 11g Training on 29JAN1010 Oracle
  • Kernel Parameter setting explaination for Processes Parameter Linux/Unix
  • Renaming the column name Oracle
  • Oracle GoldenGate lag monitoring shell script Linux/Unix
  • initUOCIOTTO.ora Oracle
  • Search and replace editor command in vi Linux/Unix
  • Sending SQLPLUS output in HTML format Oracle
  • Shuffle an array PHP/MYSQL/Wordpress
  • create database link syntax Oracle
  • reset Sequence Oracle
  • logminer and my_lbu Oracle
  • import-export with multiple files Oracle
  • handling filenname with space Linux/Unix
  • age_alert.ksh aging out alert.log Linux/Unix
  • Good Doc 28-JUN-2006 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

  • Useful Solaris Commands on 28-SEP-2005 Linux/Unix
  • ipcs -l Linux/Unix
  • Removing Ctrl-M from end of line using vi Linux/Unix
  • xargs use Linux/Unix
  • To find all disk io ( EMC as well as local) Linux/Unix
  • remove archfiles only when it is applied to DR rm_archfiles.sh 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
  • Find execution plan from dba_hist_sql_plan for a specific SQL_ID and PLAN_HASH_VALUE fplan.sql Oracle
  • How to specify 2 arch location to avoid any kind of DB hanging. Oracle
  • oracle 11g RAC on vmware Oracle
  • Oracle Data Direct to TAPE Oracle
  • Ports used by Oracle Software Oracle
  • Caching sequence in Memory Oracle
  • find checksum of a file. Linux/Unix
  • note id 373303.1 Linux/Unix

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme