Replacing old TNS entries with New one in multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing old TNS entries with New one in multiple files
# 1  
Old 05-22-2014
Oracle Replacing old TNS entries with New one in multiple files

I have requirement to replace old TNS entries with New one in multiple files.
one file may contain more then one occurrence of tns.

Example: Below is the one of occurrence in a current file(s). i am interested to replace only red part.

Code:
<connection-pool name="Google_APP_CP" inactivity-timeout="20" initial-limit="10" max-connections="40" min-connections="10" validate-connection="true">
      <connection-factory factory-class="oracle.jdbc.pool.OracleDataSource" user="APP1" password="oracle_app#@%$" url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=apap1-vip.mydomain.com)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=apap2-vip.mydomain.com)(PORT=1521))(LOAD_BALANCE=yes)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=SID.mydomain.com)(FAILOVER_MODE=(TYPE=SELECT)(METHOD=BASIC)(RETRIES=180)(DELAY=5))))" commit-record-table-name=""/>
   </connection-pool>

After replace, It should be like below:
Code:
<connection-pool name="Test_APP_CP" inactivity-timeout="20" initial-limit="10" max-connections="40" min-connections="10" validate-connection="true">
      <connection-factory factory-class="oracle.jdbc.pool.OracleDataSource" user="APP1" password="oracle_app#@%$" url="jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS=(PROTOCOL=TCP)(HOST=mydomain-scan)(PORT=1621))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=NEWSID.mydomain.com)))" commit-record-table-name=""/>
   </connection-pool>

There should not be any change other then this replace, otherwise application will not read the file. (even 1 extra space is not tolerable )
# 2  
Old 05-22-2014
You can do that with sed and its s (substitute) command.
For example the following provides a good match:
Code:
sed 's/\(url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)\).*\())"\)/\1new text\2/' file

The delimiter / must not occur in the strings (otherwise another character can be taken).
Two parts of the search expression are in \( \) and can be put back by \1 and \2.
The .* (everything) in between is replaced by the new text.
# 3  
Old 05-30-2014
Can you please make search and replace for me.
# 4  
Old 09-20-2014
This is not working...anyone can suggest some other solution.
# 5  
Old 10-04-2014
What is not working? Please describe what happened.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Issue with search and replacing multiple items in multiple files

Im having an issue when trying to replace the first column with a new set of values in multiple files. The results from the following code only replaces the files with the last set of values in val.txt. I want to replace all the files with all the values. for date in {1..31} do for val in... (1 Reply)
Discussion started by: ncwxpanther
1 Replies

2. Shell Programming and Scripting

sed parser behaving strange on replacing multiple words in multiple files

I have 4000 files like $cat clus_grp_seq10_g.phy 18 1002 anig_OJJ65951_1 ATGGTTTCGCAGCGTGATAGAGAATTGTTTAGGGATGATATTCGCTCGCGAGGAACGAAGCTCAATGCTGCCGAGCGCGAGAGTCTGCTAAGGCCATATCTGCCAGATCCGTCTGACCTTCCACGCAGGCCACTTCAGCGGCGCAAGAAGGTTCCTCG aver_OOF92921_1 ... (1 Reply)
Discussion started by: sammy777888
1 Replies

3. Shell Programming and Scripting

Replacing matched patterns in multiple files with awk

Hello all, I have since given up trying to figure this out and used sed instead, but I am trying to understand awk and was wondering how someone might do this in awk. I am trying to match on the first field of a specific file with the first field on multiple files, and append the second field... (2 Replies)
Discussion started by: karlmalowned
2 Replies

4. Shell Programming and Scripting

Grep all lines with the string "TNS-" but skip those with "TNS-12514"

Platform: Oracle Linux 6.3 From a log file, I want to grep all lines with the pattern "TNS-" but I want to skip those with the pattern "TNS-12514" . How can I do this ? (3 Replies)
Discussion started by: John K
3 Replies

5. Shell Programming and Scripting

Replacing multiple extensions

HI, I have some csv files with mutiple extensions, I want to remove all the extensions and keep only the .csv extension. anybody can suggest me how to do this. source files 1.txt.csv.txt.csv.csv.txt.csv 2.csv.txt.csv.txt.csv.txt target 1.csv 2.csv --Wang (1 Reply)
Discussion started by: wangkc
1 Replies

6. UNIX for Dummies Questions & Answers

best method of replacing multiple strings in multiple files - sed or awk? most simple preferred :)

Hi guys, say I have a few files in a directory (58 text files or somthing) each one contains mulitple strings that I wish to replace with other strings so in these 58 files I'm looking for say the following strings: JAM (replace with BUTTER) BREAD (replace with CRACKER) SCOOP (replace... (19 Replies)
Discussion started by: rich@ardz
19 Replies

7. Shell Programming and Scripting

Replacing text from multiple files at multiple location

Hi, I have many files scattered in all different folders. I want to replace the text within all the files using a single command ( awk, sed...) Is it possible? example find all the files in which there is text "memory" and replace it with "branded_memories". the files can be at the... (2 Replies)
Discussion started by: rudoraj
2 Replies

8. Shell Programming and Scripting

Replacing string in multiple files

Hi, I need to replace the string 'abcd' with 'xyz' in a file sample.xml This sample.xml is also present in the subdirectories of the current directory. Eg, If I am in /user/home/ the sample.xml if present in /user/home/ /user/home/folder1/ /user/home/folder2/... (3 Replies)
Discussion started by: arulanandsp
3 Replies

9. Shell Programming and Scripting

renaming multiple files while replacing string

hi, i've found a few examples of scripts to do this but for some reason can't get them to work properly. basically i have some dirs with a few hundred files mixed in with a bunch of other files that were made with a typo in part of them. long-file-names-tyo-example.ext want to be able... (2 Replies)
Discussion started by: kevin9
2 Replies

10. Shell Programming and Scripting

replacing multiple lines

i have a file : sample1.txt OBJECT="POINT" ACTION="REDEFINE" POINT_NAME="ABCD001G " GHYT_POPRIORITY_1="1" GHYT_POPRIORITY_2="1" GHYT_POPRIORITY_3="1" GHYT_POPRIORITY_4="1" GHYT_POPRIORITY_USER="1" HIGH_ALARM_PRIORITY_1="1" HIGH_ALARM_PRIORITY_2="1" HIGH_ALARM_PRIORITY_3="1" ... (1 Reply)
Discussion started by: ajnabi
1 Replies
Login or Register to Ask a Question