ShaunLangley
ShaunLangley

Reputation: 342

text substitution

I have a list of files that are in the form foo001.h21.tif that I need to rename. I know how to substitute strip off the end of the filename, but not the beginning. I basically need to strip it so it can be saved as 001.h21.tif. Normally I would use:

for i in *.tif; do mv $i ${i%%.tif}; done

to capture everything preceding .tif. Can someone help me with figuring out how to go the opposite way?

THanks!

Upvotes: 0

Views: 106

Answers (1)

ruakh
ruakh

Reputation: 183484

% and %% are to suffixes what # and ## are to prefixes. In your case, you can write:

for filename in foo*.tif; do mv "$filename" "${filename#foo}"; done

See §3.5.3 "Shell Parameter Expansion" in the Bash Reference Manual.

Upvotes: 1

Related Questions