

In that case, wrap the appropriate variables in quotes, like: NB: mv will fail if any of the file names in the renaming operation has spaces in it. Now rename your file as needed: mv $old_name $new_name.txt) gone as well, set new_name variable as: new_name=$(ls | grep $p | tr ':-' '_' | sed 's/_\./\./') If you want the last underscore (just before the. If for uniformity's sake you want to replace the dashes ( -) along with the colons ( :) with underscores ( _), you can do this: new_name=$(ls | grep $p | tr ':-' '_') ī.

Store the new file name with necessary character replacements: new_name=$(ls | grep $p | sed 's/:/_/g') # Using 'sed' Store the old file name you want to rename: old_name=$(ls | grep $p).Store the pattern of the file name you are targeting as a variable: p="201*".If you have just one or a few files, this can do the renaming for you:
