Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing a word in all lines in file based on another field value 1

Status
Not open for further replies.

TheDash

MIS
Mar 25, 2004
171
US
Hello all,
I have a file with many lines like below and several other small lines in it. For all lines that begin with CREATE DATABASE LINK I have to replace <PWD> (i.e field 10) with <field 7>_ppp . field7 is not constant and it varies from one line to other. It needs to be dynamically sustituted. Shown it below in detail, could some one help with me with the substitution?

Before:


CREATE DATABASE LINK "abc.com" CONNECT TO testuser IDENTIFIED BY <PWD> USING 'abc.com';

After replace, the line should become.

CREATE DATABASE LINK "abc.com" CONNECT TO testuser IDENTIFIED BY testuser_ppp USING 'abc.com';


Will appreciate your help. Thanks in advance.
 
One way:
Code:
awk '/^CREATE DATABASE LINK /{sub(/<PWD>/,$7"_ppp")}1' /path/to/input >output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top