Solved

Replace string inside block

Posted on 2013-10-24
1
136 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

14 Experts available now in Live!

Get 1:1 Help Now