Question: This works fine:

```
printf "%s\n" data_{1..10} | sed -n '/_2$/ s/a/e/gw file'

```

But if I try something like this:

```
printf "%s\n" data_{1..10} | sed -n '/_2$/ { s/a/e/gw file }'

```

I get:

```
sed: -e expression #2, char 0: unmatched `{'

```

If I replace `w file` with `p` it works fine inside `{}`. This works:

```
printf "%s\n" data_{1..10} | sed -n '/_2$/ { s/a/e/gp }'

```

So, why `w` works without `{}` and why not inside `{}`? and how can I use it inside `{}`?

Answer: 
Use an attribute to keep track of the levels:

```
function moveForward() {
    $(“.before”).each(function() {
        $(this).attr(“data-pos”, $(this).attr(“data-pos”) + 1);
    }
    $(“.after”).each(function() {
        $(this).attr(“data-pos”, $(this).attr(“data-pos”) - 1);
    }
    $(“.active”).toggleClass(“active before”).attr(“data-pos”, 1);
    $(“.after[data-pos=‘0’]”).toggleClass(“after active”);
}

function moveBack() {
    $(“.before”).each(function() {
        $(this).attr(“data-pos”, $(this).attr(“data-pos”) - 1);
    }
    $(“.after”).each(function() {
        $(this).attr(“data-pos”, $(this).attr(“data-pos”) + 1);
    }
    $(“.active”).toggleClass(“active after”).attr(“data-pos”, 1);
    $(“.before[data-pos=‘0’]”).toggleClass(“before active”);
}

```

Of course you can call these multiple times (or modify them) to change by multiple entries, and track the position in a variable to allow for a “go to position” function.

And then your css:

```
/* any pos greater than 9 */
.before, .after {
    opacity: 0;
}

/* these selectors should be sufficient because ‘.active’ will always have no ‘data-pos’ or will have a ‘data-pos’ of 0 */
[data-pos=‘1’] {
    opacity: 0.9;
}

[data-pos=‘2’] {
    opacity: 0.8;
}
/* values 3-9 here */

```

And make sure your html is pre-set correctly, e.g.

```
<div class=“before” data-pos=“2”/>
<div class=“before” data-pos=“1”/>
<div class=“active”/>
<div class=“after” data-pos=“1”/>
<div class=“after” data-pos=“2”/>
<div class=“after” data-pos=“3”/>
<div class=“after” data-pos=“4”/>

```
If I understood correctly you want to decrease the opacity of **LI**s from the active one to the end. If this is the case the snippet is:

```js
var elements = $('.years.active').nextAll('.years').andSelf();
var step = 1 / (1 + elements.length);
var startValue = 1;
elements.each(function(idx, ele) {
    startValue = startValue - 0.1;
    console.log('New opacity is (li:' + ele.textContent + '):' + startValue);
    $(ele).css('opacity',startValue);
})
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="pagespan container">
    <div class="wrap">
        <div class="frame" id="forcecentered">
            <ul class="clearfix">
                <li data-target="1997" class="years">1997</li>
                <li data-target="2009" class="years">2009</li>
                <li data-target="2010" class="years">2010</li>
                <li data-target="2013" class="years active">2013</li>
                <li data-target="2015" class="years">2015</li>
                <li data-target="2016" class="years">2016</li>
                <li data-target="2017" class="years">2017</li>
            </ul>
        </div>
    </div>
</div>
```