Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Proc code Oracle
  • database trigger failing Oracle
  • find_err.sql for finding errors from dba_errors. Oracle
  • Specify the Rollback segment to use in Transaction Oracle
  • Oracle 10g Wait Model Oracle
  • findobj.sql Oracle
  • Gathering statistics with DBMS_STATS Oracle
  • Drop all SPM baselines for SQL handle Oracle
  • changing kernel parameter in Oracle Enterpise Linux Linux/Unix
  • Unix split command to split files Linux/Unix
  • PLSQL Table Syntax 1 Oracle
  • oracle Dba site Oracle
  • Absolute file number and relative file number Oracle
  • telnet listening Linux/Unix
  • DBMS_Shared_pool pinning triggers 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 Linux/Unix
  • Unix split command to split files Linux/Unix
  • Removing Blank lines from file using grep Linux/Unix
  • How to find Unix server conguraiton including Server Model number and underlying disk sub-system ( On Solaris) Linux/Unix
  • Zip and unzip with tar Linux/Unix
  • avail.sh ( find filesystem spae usage) Linux/Unix

Leave a Reply Cancel reply

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

Categories

  • Ansible (0)
  • AWS (2)
  • Azure (1)
  • Django (0)
  • GIT (1)
  • Linux/Unix (149)
  • MYSQL (5)
  • Oracle (395)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (1)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (150)
  • SQL scripts (343)
  • SQL Server (6)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • prepfiles.sh for step by step generating pending statistics files10-Mar-2026
  • tracksqltime.sql05-Mar-2026
  • Complete Git Tutorial for Beginners25-Dec-2025
  • Postgres DB user and OS user.25-Dec-2025
  • Trace a SQL session from another session using ORADEBUG30-Sep-2025
  • SQL Server Vs Oracle Architecture difference25-Jul-2025
  • SQL Server: How to see historical transactions25-Jul-2025
  • SQL Server: How to see current transactions or requests25-Jul-2025
  • T-SQL Vs PL/SQL Syntax25-Jul-2025
  • Check SQL Server edition25-Jul-2025

Archives

  • 2026
  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • How to Modify the statistics collection by MMON for AWR repository Oracle
  • restarting network in linux Linux/Unix
  • MYSQL and Oracle Comparison for Oracle DBA MYSQL
  • TNSNAMES entries details Oracle
  • Good links for x$ tables in oracle. Oracle
  • New OFA for 11g Oracle
  • Find_stale_dr.sql finding stale physical DR.. Oracle
  • get_aix_vmstat.ksh Oracle

Copyright © 2026 pvmehta.com.

Powered by PressBook News WordPress theme