Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Monitor Long Running Job Oracle
  • CPU Core related projections AWS
  • online_bkup.sql Oracle
  • Btee and Bitmap Plans in Oracle 9i and higher Oracle
  • Gather Stats manually using DBMS_STATS after disabling DBMS_SCHEDULER jobs as previous entry Oracle
  • 556976.1 Oracle Clusterware: Components installed Oracle
  • Vivek Tuning for Row Locks. Oracle
  • run this before doing any dbchange pvm_pre_change.sql Oracle
  • Absolute file number and relative file number Oracle
  • exp syntax in oracle 10g Oracle
  • Metalink Note: Note:250655.1 : ADDM Basics USING THE AUTOMATIC DATABASE DIAGNOSTIC MONITOR Oracle
  • TRUNCATE table and disabling referential constraints. Oracle
  • Optimizer_Index init.ora parameter explaination. Oracle
  • myfile Oracle
  • move_arch_files.ksh Linux/Unix

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

  • telnet listening Linux/Unix
  • fdisk -l explaination about Primary-Logical-Extended Partitions Linux/Unix
  • How to collect CPU usage on Linux using Shell script Linux/Unix
  • Running select from V$ views from remote server Linux/Unix
  • fuser to check who is using diretory Linux/Unix
  • cold backup scripts to copy locally 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 (388)
  • PHP/MYSQL/Wordpress (10)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (337)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • 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
  • Reading config file from other folder inside class24-Sep-2024
  • Python class import from different folders22-Sep-2024
  • Transfer SQL Profiles from One database to other database.05-Sep-2024
  • Load testing on Oracle 19C RAC with HammerDB18-Jan-2024

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • oracle_env_10g_CADEV Linux/Unix
  • changing kernel parameter in Oracle Enterpise Linux Linux/Unix
  • ORA-01220 Oracle
  • fkwoindex.sql /* Find FK without Index */ Oracle
  • How can I tell if ASO is installed ? Oracle
  • Find average Row Length and other table size calculation. metalink notes Oracle
  • rm_backup_arch_file.ksh Linux/Unix
  • To find all disk io ( EMC as well as local) Linux/Unix

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme