Solved

Replace string inside block

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
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…
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…

856 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