Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to replace all but last matching in a file using bash?
    primarykey
    data
    text
    <p>Assuming using <b>bash</b>, having a configuration file like:</p> <blockquote> <ol> <li>param-a=aaaaaa</li> <li>param-b=bbbbbb</li> <li><b>param-foo=first occurence &lt;-- Replace</b></li> <li>param-c=cccccc</li> <li><b><i># param-foo=first commented foo &lt;-- Commented: don't replace</i></b></li> <li>param-d=dddddd</li> <li>param-e=eeeeee</li> <li><b>param-foo=second occurence &lt;-- Rreplace</b></li> <li><b>param-foo=third occurence &lt;-- Last active: don't replace</b></li> <li>param-x=xxxxxx1</li> <li>param-f=ffffff</li> <li><b><i># param-foo=second commented foo &lt;-- Commented: don't replace</i></b></li> <li>param-x=xxxxxx2</li> </ol> </blockquote> <p>In which you can find multiple commented or uncommented lines of the param-foo, how can you comment all the uncommented param-foos except the very last active one, resulting in:</p> <blockquote> <ol> <li>param-a=aaaaaa</li> <li>param-b=bbbbbb</li> <li><b># param-foo=first occurence &lt;-- Replaced</b></li> <li>param-c=cccccc</li> <li><b><i># param-foo=commented foo &lt;-- Left</i></b></li> <li>param-d=dddddd</li> <li>param-e=eeeeee</li> <li><b># param-foo=second occurence &lt;-- Replaced</b></li> <li><b>param-foo=third occurence &lt;-- Left</b></li> <li>param-x=xxxxxx1</li> <li>param-f=ffffff</li> <li><b><i># param-foo=second commented foo &lt;-- Left</i></b></li> <li>param-x=xxxxxx2</li> </ol> </blockquote> <p>Two parts of the question:<br> 1. How to do it with only one <b>known repeating</b> param?<br> (only param-foo in the example above) <br><br> 2. How to do it with all multiple active params at once? <br>(param-foo + param-x in the example above)<br> <b>Attention: In this case I don't know previously the name of the repeating params!</b></p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload