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!

Pattern matching and word substitution

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello,
Does anyone know how to modify certain words in a file. Like for example replacing the word Variable by 100. For example, the it is in the form <TAG>Variable<\TAG>.
Please advice.
Thanks,
GTFY
 
Hi,

you can use sed command like this :
VAR=100
VAR2=102
sed -e &quot;s%variable%$VAR%&quot; -e &quot;s%variable2%$VAR2%&quot; file

Regards.

fcail
 


Hi GTFY!

You can also use awk to do this job:

Code:
awk &quot;/TAG/ { gsub(/Variable/,100) } { print }&quot; file.xml

This code changes each line of file.xml that contains string 'TAG'.

Even better regular expression is /<TAG>/ (or /\<TAG\>/).

Bye!

KP.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top