I am trying to create a small Bash script to remove hyphens from a filename. For example, I want to rename:
CropDamageVO-041412.mpg
to
CropDamageVO041412.mpg
I'm new to Bash, so be gentle :] Thank you for any help
I am trying to create a small Bash script to remove hyphens from a filename. For example, I want to rename:
CropDamageVO-041412.mpg
to
CropDamageVO041412.mpg
I'm new to Bash, so be gentle :] Thank you for any help
or, of course,
Try this:
That's assuming that your directories don't have dashes in the name. That would break this.
The
${varname//regex/replacementText}
syntax is explained here. Just search for substring replacement.Also, this would break if your directories or filenames have spaces in them. If you have spaces in your filenames, you should use this:
This has the disadvantage of having to be run in every directory that contains files you want to change, but, like I said, it's a little more robust.
The backticks (``) tell bash to run the command inside them and use the output of that command in the expression. The sed part applies a regular expression to remove the hyphens from the filename.
Or to do this to all files in the current directory matching a certain pattern: