Unix/linux command to remove specific matching text from all files. In this case, I had a list of tiles that had
-defaults.properties suffix. I wanted to rename them all so that they had just
.properties suffix instead. For example, if a file was named
connection-defaults.properties, I wanted it to be renamed to
As usual, rather than wasting my time and doing it manually 100 times, I set myself to find an automated way of doing it. And sure enough, I found it!
Here it is:
for f in *-defaults.properties; do mv "$f" "$(echo "$f" | sed s/-defaults//)"; done
The above command finds all files that end with
-defaults.properties. For each file that match that criteria, we then rename it to a name that has
-defaults stripped out. To strip out the name, we use
sed command and to rename we use
Tested on mac running oh-my-zsh.