Bash Q: How to remove brackets from mp3 files?
Hi,
I am newb to shell scripting and i wanted to remove brackets from my mp3 files. The format is Abc [abc].mp3 I need Abc.mp3 i know that i can use either regex or sed to do this.....but not able to come up with solution. If you can explain a bit about your solution...it will help me learn scripting. Thanks. |
Hi, welcome to LQ!
Code:
echo 'Abc [abc].mp3'|sed -r 's/^([^][]+) \[.+\](\..*)$/\1\2/' Search (and remember) for all characters from beginning of line that aren't brackets: Code:
^([^][]+) Code:
\[.+\] Find & remember everything from the dot to the end of line: Code:
(\..*)$ Replace the whole line with the two remembered bits: Code:
\1\2 Cheers, Tink P.S.: sed or regex makes little sense, in sed you commonly heavily rely on regex. |
Thanks Tinkster.
I never want turn-key answers....it hinders development of skills.
|
Quote:
Just thought I'd clarify that. ;} Cheers, Tink |
is this correct?
^([^][]+)
i understood your solution except for the above part. correct me if i got this wrong..... the () tells linux to save this in memory. the starting ^ indicates the beginning of the line... does [^] say anything other than and []+ say one or more brackets? i need some work on character sets.... |
Quote:
Code:
^([^][]+) and the parenthesis indeed mark what's to be remembered. [^][] is a character class of all characters that aren't a ] or a [, and the + is simply "more than one of anything not a [ or ]". HIH Cheers, Tink |
Beautiful.
Thanks Tinkster. Understood everything.
|
All times are GMT -5. The time now is 07:40 PM. |