Question: I want to remove the extensions and prefixes from these files:

```
awstats.www.test1.com.conf
awstats.www.test2.com.conf
awstats.www.test3.com.conf

```

I need to remove `awstats.` and `.conf`, but leave files like `www.test1.com` unchanged. How can I do this?

Answer: 
Assuming that you are in the same directory as your files:

```none
for name in awstats.*.conf; do
    basename "${name#awstats.}" .conf
done

```

The code inside the loop will first trim the `awstats.` prefix off from `$name` using a standard parameter substitution, and then lets `basename` trim off the `.conf` suffix.

You could also do it in two steps without calling `basename`:

```none
for name in awstats.*.conf; do
    newname=${name#awstats.}  # trim off prefix
    newname=${newname%.conf}  # trim off suffix
    printf '%s\n' "newname"
done

```

No files are renamed by these two loops.
I assume `rename` (`perl-rename` on some systems, just `rename` on others) is simplest here:

```
rename 's/^awstats\.//;s/\.conf$//' awstats.*.conf

```

Explanation of the regex:

* `s/^awstats\.//` substitute `awstats.` at beginning of line (filename) with nothing
* `s/\.conf$//` substitute `.conf` at end of line (filename) with nothing

Use the `-n` option to do a dry-run!