?
Solved

Replace string inside block

Posted on 2013-10-24
1
Medium Priority
?
142 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 19

Accepted Solution

by:
simon3270 earned 1000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

770 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