Looking to run a script on the server to look at a path of a file and replace a word whereas it matches in the div.
So need to replace _toself to viewers where author equals a certain email test@example.com
URL=/var/www/sever/temp/fhyw1
FILE=user.txt
<div class='entry'>
<div class='pageurl'>temp/fhyw1</div>
<div class='context'>text</div>
<div class='subject'>testing</div>
<div class='notetext'></div>
<div class='signed'>USER</div>
<div class='author'>test@example.com</div>
<div class='color'>0</div>
<div class='visibility'>shared</div>
<div class='to'>_toself</div>
<div class='num'>4</div>
</div>
<div class='entry'>
<div class='pageurl'>temp/fhyw1</div>
<div class='context'>text</div>
<div class='subject'>testing</div>
<div class='notetext'></div>
<div class='signed'>USER</div>
<div class='author'>user@example.com</div>
<div class='color'>0</div>
<div class='visibility'>shared</div>
<div class='to'>_viewers</div>
<div class='num'>4</div>
</div>
This sed solution might work for you:
N.B. You will need to replace
SUBSTITUE TEXTwith theviewers,_viewersor whateverThe
sedcommand allows all lines other than those between<div class=.entry.>and</dev>(.allows for single'or double quotes") to pass through unchanged. If the line begins with<div class=.entry.>it is copied to a register call the hold space (HS) and then the pattern space (PS) is deleted. All other lines are appended to the HS and then deleted accepting the line</div>. When this line appears the HS is swapped with the PS and if this multiline containsauthor.>test@example.comthenSUBSTITUTE TEXTis substituted for_toself. The multiline is printed out regardless, then the PS replaces the HS and it in turn to printed out.