Question: I have the following: `param="/var/tmp/test"`
I need to replace the word `test` with another word such as `new_test`

need a smart way to replace the last word after "/" with sed

Answer: 
Extracting bits and pieces with `sed` is a bit messy (as Jim Lewis says, use `basename` and `dirname` if you can) but at least you don't need a plethora of backslashes to do it if you are going the `sed` route since you can use the fact that the delimiter character is selectable (I like to use `!` when `/` is too awkward, but it's arbitrary):

```
$ echo 'param="/var/tmp/test"' | sed ' s!/[^/"]*"!/new_test"! '
param="/var/tmp/new_test"

```

We can also extract just the part that was substituted, though this is easier with two substitutions in the `sed` control script:

```
$ echo 'param="/var/tmp/test"' | sed ' s!.*/!! ; s/"$// '
test

```
This might work for you:

```
echo 'param="/var/tmp/test"' | sed -r 's#(/(([^/]*/)*))[^"]*#\1newtest#'
param="/var/tmp/newtest"

```