Sponsored Content
Full Discussion: To Replace a line in a file
Top Forums Shell Programming and Scripting To Replace a line in a file Post 302898143 by Stars_perform on Saturday 19th of April 2014 03:11:45 AM
Old 04-19-2014
To Replace a line in a file

Hi Folks,

I am trying to replace large string(jdbc url) in a property file. I have many such property files in subfolders where i need to replace jdbc url. Below is the code that i have tried but it does not work.
Need your suggestions for the same.

.property file will have value like below.
Code:
JDBC_URL=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=stora.com)(PORT=1521))(LOAD_BALANCE=YES)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=STYU)(FAILOVER_MODE=
(TYPE=SELECT)(METHOD=BASIC)(RETRIES=180)(DELAY=5))))"
 
INSTALL_ID=KTJUM


change.sh is the file where i am writing below code:


Code:
NEW="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=stem.com)(PORT=1521))(LOAD_BALANCE=YES)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=uyet)(FAILOVER_MODE=
(TYPE=SELECT)(METHOD=BASIC)(RETRIES=180)(DELAY=5))))"
 
 
for file in `find . -name *.properties`
do 
cat $file |grep -iw "JDBC_URL"|cut -d '@' -f2|read OLD
echo "perl -i -p -e 's/$OLD/$NEW/g' $file" |sh
done

OLD variable contains below string from file:
Code:
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=stora.com)(PORT=1521))(LOAD_BALANCE=YES)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=STYU)(FAILOVER_MODE=
(TYPE=SELECT)(METHOD=BASIC)(RETRIES=180)(DELAY=5))))"

When i do this, the OLD string is not getting replaced with new String. But when i do the same thing for other line in file like install_id, the perl command works.

Please suggest what i am missing in the code and how better i can work.


PS: there is no underline for delimiter @ but i dont why i am getting here in the above i tried undoing the underline but it isnot working. Please ignore the underline.

Last edited by Scrutinizer; 04-19-2014 at 06:08 AM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to replace a line in file with blank line

Hi I nned cmd to which will help me to replace a line in file with blank line e.g. file1 a b c d e after running cmd I shud get file1 b c d e (5 Replies)
Discussion started by: tarunn.dubeyy
5 Replies

2. Shell Programming and Scripting

Read file and for each line replace two variables, add strings and save output in another file

Hi All, I have a file, let's call it "info.tmp" that contains data like this .. ABC123456 PCX333445 BCD789833 I need to read "info.tmp" and for each line add strings in a way that the final output is put /logs/ua/dummy.trigger 'AAA00001.FTP.XXX.BLA03A01.xxxxxx(+1)' where XXX... (5 Replies)
Discussion started by: Andy_ARG
5 Replies

3. Shell Programming and Scripting

Optimised way for search & replace a value on one line in a very huge file (File Size is 24 GB).

Hi Experts, I had to edit (a particular value) in header line of a very huge file so for that i wanted to search & replace a particular value on a file which was of 24 GB in Size. I managed to do it but it took long time to complete. Can anyone please tell me how can we do it in a optimised... (7 Replies)
Discussion started by: manishkomar007
7 Replies

4. Shell Programming and Scripting

sed to replace a line with modified line in same file

i have few lines in a file... i am reading them in a while loop so a particular line is held is $line1.. consider a modified line is held in $line2.... i want to replace $line1 with $line2 in the same file... how to do it..? i have come up till the below code sed "s/$line1/$line2/g" tmpfile.sql... (5 Replies)
Discussion started by: vivek d r
5 Replies

5. Shell Programming and Scripting

Replace line in file with line in another file based on matching string

Hi I am not the best scripter in the world and have run into a issue which you might be able to guide me on... I have two files. File1 : A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB File2: C345,... (5 Replies)
Discussion started by: luckycharm
5 Replies

6. Shell Programming and Scripting

Replace Each Line Of A File

Hi All, I want to repalce each line of a file by a constant value using awk. I do not need to match the pattern and replace and I also do not need to perform replace for selected lines of file. Every line in the file will be replace by the constant value. I searched every where and did not... (2 Replies)
Discussion started by: angshuman
2 Replies

7. Shell Programming and Scripting

Replace and add line in file with line in another file based on matching string

Hi, I want to achieve something similar to what described in another post: The difference is I want to add the line if the pattern is not found. File 1: A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB ... (11 Replies)
Discussion started by: jyu3
11 Replies

8. Shell Programming and Scripting

Replace line in file with line in another file based on matching string

HI Can any one guide me how to achieve this task. I have 2 files env.txt #Configuration.Properties values identity_server_url = http://identity.test-hit.com:9783/identity/service/user/register randon_password_length = 6 attachment_file_path = /pass/temp/attachments/... (1 Reply)
Discussion started by: nikilbr86
1 Replies

9. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

10. Shell Programming and Scripting

Replace line for another line in file

Hey, i have been struggeling to find the answer myself so this is the best forum has alwyas help me :) i have an API that get data from a provider via curl. the data comes like this : AccountCode1234 CompneyNameA Credit: 200 AccountCode5678 CompneyNameB Credit: 200 AccountCode999... (3 Replies)
Discussion started by: batchenr
3 Replies
asadmin-create-jdbc-resource(1AS)				   User Commands				 asadmin-create-jdbc-resource(1AS)

NAME
asadmin-create-jdbc-resource, create-jdbc-resource - registers the JDBC resource SYNOPSIS
create-jdbc-resource --user admin_user [--password admin_password] [--host localhost] [--port 4848] [--secure|-s] [--passwordfile filename] [--terse=false] [--echo=false] [--interactive=true] --connectionpoolid ID [--enabled=true] [--description text] jndi_name Registers the JDBC resource. This command is supported in remote mode only. OPTIONS
--user authorized domain application server administrative username. --password password to administer the domain application server. --host machine name where the domain application server is running. --port port number of the domain application server listening for administration requests. --secure if true, uses SSL/TLS to communicate with the domain application server. --passwordfile file containing the domain application server password. --terse indicates that any output data must be very concise, typically avoiding human-friendly sentences and favoring well- formatted data for consumption by a script. --echo setting to true will echo the command line statement on the standard output. --interactive prompts you for the required options that are not already specified. --connectionpoolid name of the JDBC connection pool. If two or more JDBC resource elements point to the same connection pool element, they will use the same pool connections at runtime. --enabled determines whether the resource is enabled at runtime. --description text description of the JDBC resource. OPERANDS
jndi_name JNDI name for resource to be created. Example 1: Using the create-jdbc-resource command asadmin> create-jdbc-resource --user admin1 --password adminadmin1 --host pigeon --port 5001 --connectionpoolid XA_connection_pool --description "creating a sample jdbc resource" sample_jdbc_resource Command create-jdbc-resource executed successfully Where: sample_jdbc_resource is the resource that is created. EXIT STATUS
0 command executed successfully 1 error in executing the command asadmin-delete-jdbc-resource(1AS), asadmin-list-jdbc-resources(1AS) J2EE 1.4 SDK March 2004 asadmin-create-jdbc-resource(1AS)
All times are GMT -4. The time now is 02:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy