Solved

Replace string inside block

Posted on 2013-10-24
1
134 Views
Last Modified: 2013-11-26
Hi,
I have file with a lot of blocks like below:

 <a
   id="LISTENER_E"
   xlink:href=""
   transform="matrix(0.62637352,0,0,0.33836976,-278.11964,466.9526)">
   <image
   id="LISTENER_E.image"
   xlink:href="/images/Mobile/Icons/Catalog_Grey_4.png"
   height="65"
   width="65"
   y="502.32147"
   x="1087.6489" />
</a>

I have variables with name like id : LISTENER_E=Red

What I need:
According to variable name, replace "Grey" with variable value  into corresponding block
and do it without tmp files (like sed -i)
0
Comment
Question by:IKeystone
1 Comment
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 39599687
I'm not sure I quite understand.

Do you have a series of varables in some other location (e.g. in another file) such as:
  LISTENER_E=Red
  LISTENER_K=Blue
and so on, and if the "id=" line has LISTENER_E you want to replace "Grey" on the xlink line with "Red", and if "id=" has LISTENER_K you want to replace "Grey" with "Blue"?

Will the layout always be as you have shown, with each item on a separate line?

Are there "<a" entries in the file which *don't* have an "id=xxx" line and which don't need the "Grey" bit to be repaced?

By the way, "sed -i" uses temporary files - it's just that it hides that from the user.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Powershell script to return group membership 8 64
unix scripting question 1 76
Changing $PATH variable - OS X 2 55
Backing Up Ipset 9 65
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now