How do you remove Parenthesis from filenames using sed
Hello,
I have filenames like such: abc (e).doc And I want to rename them to abc.doc I have a directory full of files names like this. How can i do this using the sed command? I have looked online for about 2-3 hours now and am frustrated that I can't find an answer. Any help will be most appreciated -Thanks |
Quote:
Code:
sed 's/[()]//g' Code:
#!/bin/bash |
It's close. only issue is i need to have it remove those pesky e's between the ( and ).
Also, the space before the first ( needs to be removed. Any ideas? -Thanks |
Quote:
|
I understand where you're going here, but the issue is that it removes all of the letters I input in there. Some of the filenames have (e) and some have (L)...so when i put an e or an L in there, all e's and all L's from all the filenames are deleted.
I only want to remove the sequence of (e) and (L). Not sure how to do that. |
Quote:
Code:
x=${i//[\(\)]/} Code:
x=${i//[ \(e\)]/} |
Code:
sed 's/\([[:alnum:]]*\)[[:space:]]*(.)\(\..*\)/\1\2/' file |
Quote:
|
OK, I am trying, please don't think I'm just here looking for the easy answer. Sed is just so complex and because it can do so much, I'm having a hard time understanding why you put certain characters in certain places.
Anyhow, about your examples below: x=${i//[ \(e\)]/} x=${i//[ \(L\)]/} They remove all the spaces in the filenames. While they do get rid of my (L) and (e) issue, now the files have no spaces, so that's not good. What am I doing wrong here? -Thanks for the help |
Quote:
Code:
x=${i//[ \(e\)]/} Code:
x=${i//[\(e\)]/} Also, what you're trying to do doesn't make much sense. If you have MANY files named "abc (e).doc", and you rename them to "abc.doc" (from your first post), you'll overwrite the first file with the second, and so on. Unless the file names are unique, you'll clobber each file with the next. |
Hello and thanks.
I was trying to keep it simple. In my first post I asked how to change abc (e).doc to abc.doc. While you did tell me a way to do it, it did not work for all my files because some have spaces that I do want to keep. I guess I should have stated that i wanted to have file abc def (e.)doc become abc def.doc I just figured it out (greatly with your help). I took out the space from your regex expression and then used the rename command to change " .doc" to just ".doc" Thanks again for the help everyone. I will be more careful in the future when asking questions. |
Quote:
The above does the job even if the input is "abc def (e).doc" It gives abc def.doc |
All times are GMT -5. The time now is 08:10 AM. |