I need to figure out how to do the below and was wondering if anyone could offer any suggestions on good sed
practices, or more importantly bad ones, that will assist me in completing this task.
Basically I want to go by line through a file and look for a match on PATTERN1. Once I have a match I want to look for the next line that matches PATTERN2. If I get a PATTERN2 match I want to move on to the next PATTERN1 match. If I dont have a match for PATTERN2 I want to modify the next occurrence of PATTERN3 and modify it. Finally modifying all matches for PATTERN1 at the PATTERN2 or PATTERN3 matches.
Take for example the below:
<tr>
<td>
<input type="text" id="record_511568" value="PATTERN1" style="width:200px">
</td>
<td>2001-06-29 18:38:21</td>
<td>2014-06-29 18:38:21</td>
<td>
<select id="status_511568">
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</td>
</tr>
I want to match PATTERN1 and check for the next occurrence of PATTERN2 (1).
Then if PATTERN2 matched I want to change it to (<option value="1" selected="selected">1</option>
)
If PATTERN2 did not match then I want to make sure it matches PATTERN3 (<option value="1" selected="selected">1</option>
)
Doing this progressively through each PATTERN1. Basically modifying a large HTML form to the values I pre-determine in a list. Any thoughts on some pitfalls I may run into or advice on multi-pattern matching with sed
.