Define
z<- as.character(c(\"1_xx xx xxx_xxxx_12_sep.xls\",\"2_xx xx xxx_xxxx_15_aug.xls\"))
such that
> z [1] \"1_xx xx x
One call to gsub (and some regex magic based on @Andrie's answer) can do this. See ?regexp for details on what I used in the pattern and replacement (back-reference) arguments.
gsub
?regexp
pattern
replacement
gsub("^(\\d+_).*_(\\d+_\\w*).xls", "\\1\\2", z) # [1] "1_12_sep" "2_15_aug"