Using grep
to extract substrings:
grep -oP 'G*_\K(.+)(?=.bw)'
# \K defines the beginning; (?=) for the string end.
# eg. extract bigwig file names
ls -lah folder/* | cut -d' ' -f 10 | grep -E 'bw' | grep -oP 'G*_\K(.+)(?=.bw)'
Source:
https://unix.stackexchange.com/questions/437405/opposite-of-k-to-keep-the-stuff-right