Change file name suffix(es) (using sed ?)
问题 I'd like to change the file name suffix from files (using a bash script), but sometimes there are files with one period and some with two. Now I use this: new_file=`echo ${file} | sed 's/\(.*\.log.*\)'${suf}'/\1.'${num}'/'` Where 'new_file' is the new file name, 'file' the original file name, '${suf}' the file's suffix and ${num} a new number. So some.log must become some.log.1 and some.log.1 must become some.log.2 . With my code some.log becomes some.log.1 , but some.log.1 remains some.log.1