echo remove_staystay... | sed 's/.*(stay.*)/1/g' stay #remove all but from last ocurrence match until end