LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-06-2012, 01:23 PM   #1
vinodub
LQ Newbie
 
Registered: Feb 2012
Distribution: ubuntu
Posts: 4

Rep: Reputation: Disabled
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.
 
Old 02-06-2012, 02:11 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi, welcome to LQ!

Code:
echo 'Abc [abc].mp3'|sed -r 's/^([^][]+) \[.+\](\..*)$/\1\2/'
Abc.mp3

Search (and remember) for all characters from beginning of line that aren't brackets:
Code:
^([^][]+)
Got space and something enclosed in brackets?
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.
 
1 members found this post helpful.
Old 02-06-2012, 05:05 PM   #3
vinodub
LQ Newbie
 
Registered: Feb 2012
Distribution: ubuntu
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks Tinkster.

I never want turn-key answers....it hinders development of skills.
 
Old 02-06-2012, 05:31 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
I never want turn-key answers....it hinders development of skills.
Good .... that statement, btw, is my signature, and not aimed at anyone in particular.
Just thought I'd clarify that. ;}



Cheers,
Tink
 
Old 02-07-2012, 12:28 PM   #5
vinodub
LQ Newbie
 
Registered: Feb 2012
Distribution: ubuntu
Posts: 4

Original Poster
Rep: Reputation: Disabled
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....
 
Old 02-07-2012, 02:11 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by vinodub View Post
^([^][]+)

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....
Let's dissect this one:
Code:
^([^][]+)
^^^^      ^
|  |not in class
|
|
|
| |character class
||------|--- remember
Beginning of line
So ... the first one you correctly interpreted as beginning of line,
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
 
Old 02-07-2012, 03:42 PM   #7
vinodub
LQ Newbie
 
Registered: Feb 2012
Distribution: ubuntu
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thumbs up Beautiful.

Thanks Tinkster. Understood everything.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
help with bash remove files script heropage Linux - Server 2 11-04-2010 08:23 AM
brackets in bash shell lipun4u Programming 3 06-19-2010 08:24 AM
Remove Folders Recursively that contain *.mp3 files size 0KB or jpeg only. Drigo Linux - Newbie 1 07-15-2009 12:37 AM
Two square brackets in bash condition tirengarfio Programming 1 07-07-2009 12:36 PM
syncing two folders where files sourcefiles without brackets[] and target files with Byenary Linux - Networking 0 04-08-2008 02:14 AM


All times are GMT -5. The time now is 02:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration