Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • oracle_env_10g_CADEV Linux/Unix
  • Some useful Unix Commands Linux/Unix
  • grep multuple patterns Linux/Unix
  • sid_wise_sql.sql Oracle
  • plan10g.sql Oracle
  • Rename Oracle Instance Name Oracle
  • dbms_job.submit example Oracle
  • set_env_dba Linux/Unix
  • Metalink Note: Note:250655.1 : ADDM Basics USING THE AUTOMATIC DATABASE DIAGNOSTIC MONITOR Oracle
  • JSON/XML Types in Oracle Oracle
  • currwaitobj.sql SQl_ID and SQL statement you can get from currwaitobj.sql Oracle
  • Oracle Release Explaination Oracle
  • Proc Compilation Oracle
  • CPU speed on solaris Linux/Unix
  • Database logon trigger issue 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

  • copying/removing directory with all its subdirectory Linux/Unix
  • replace alphabets using sed Linux/Unix
  • shutdown linux Linux/Unix
  • remove archfiles only when it is applied to DR rm_archfiles.sh Linux/Unix
  • Sort with ASCII order and Numeric Order 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

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

Recent Posts

  • 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
  • Checking SQL Server Version25-Jul-2025
  • Oracle vs MYSQL Architecture differences (For DBAs)24-Jul-2025
  • V$INSTANCE of Oracle in MYSQL24-Jul-2025
  • Day to day MYSQL DBA operations (Compared with Oracle DBA)24-Jul-2025
  • MYSQL and Oracle Comparison for Oracle DBA24-Jul-2025

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • CTAS with LONG Column for 7.x and 8 and 8i Oracle
  • Load SPM baseline from AWR Oracle
  • kill all processes from specific user in solaris. Linux/Unix
  • fdisk -l explaination about Primary-Logical-Extended Partitions Linux/Unix
  • Day to day MYSQL DBA operations (Compared with Oracle DBA) MYSQL
  • logminer and my_lbu Oracle
  • Guide to Linux System Command Mastery Linux/Unix
  • Changing the Global Database Name Oracle

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme