[SOLVED] Use sed to replace value in line that has a different match..
by Guyverix from LinuxQuestions.org on (#59FCN)
I am not sure if sed or awk is the answer for what I am attempting to do.
To put it simply, I would like sed to replace string 'online.gif' with 'offline.gif' when it matches a given hostname in the line in the file. In this example, I want to change to offline when sed sees application-api-local.test.com. However I simply cannot figure out how to make this happen, and my google-fu has not helped much either.
I have made the HTML string that I am matching against all a single line, so yes it looks like cat-barf, but seemed the most reliable to deal with a single line to match things on.
Code:<tr><td><img src="online.gif"> <a href="javascript:MM_openBrWindow('https://application-api-local.test.com','','width=800,height=600, scrollbars=1');">application-api-local.test.com</a></td><td> 15007 </td><td> NA </td><td> 16007 </td></tr>If anyone has suggestions, or even theory on how I can do this via bash, I would really appreciate it. I cannot add new languages, or get too tricky, since people on Mac, as well as Linux hosts will have to end up running this script as well in the future.
I have made it a requirement to use the GNU sed for mac, so at least they will be using the same one I am working with on Linux. Just not sure how to get any further.


To put it simply, I would like sed to replace string 'online.gif' with 'offline.gif' when it matches a given hostname in the line in the file. In this example, I want to change to offline when sed sees application-api-local.test.com. However I simply cannot figure out how to make this happen, and my google-fu has not helped much either.
I have made the HTML string that I am matching against all a single line, so yes it looks like cat-barf, but seemed the most reliable to deal with a single line to match things on.
Code:<tr><td><img src="online.gif"> <a href="javascript:MM_openBrWindow('https://application-api-local.test.com','','width=800,height=600, scrollbars=1');">application-api-local.test.com</a></td><td> 15007 </td><td> NA </td><td> 16007 </td></tr>If anyone has suggestions, or even theory on how I can do this via bash, I would really appreciate it. I cannot add new languages, or get too tricky, since people on Mac, as well as Linux hosts will have to end up running this script as well in the future.
I have made it a requirement to use the GNU sed for mac, so at least they will be using the same one I am working with on Linux. Just not sure how to get any further.