LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 08-07-2017, 05:22 PM   #1
iwtbf
Member
 
Registered: Apr 2009
Location: cybernetic space
Distribution: debian
Posts: 42

Rep: Reputation: 1
Bulk rename all 'filename.mp3?NonsenseString' to 'filename.mp3'


Sometimes when I download podcasts with newsbeuter+podbeuter I get files of the form:

Code:
filename.mp3?NonsenseString
Not sure why this occurs but I would like correct this for all files in my podcast directory. I.e for all files in ~/podcasts with filenames not ending in mp3 or ogg do the truncation:

Code:
mv filename.mp3?NonsenseString filename.mp3
And similarly for ogg files. For simplicity I think it's OK to completely disregard weird upper-lower-case permutations of '.mp3' and '.ogg'.

What is the most straightforward way of doing this?

EDIT: Just wanted to add an example:

2017-07-12-symhc-bill-berry.mp3?awCollectionId=1002&awEpisodeId=927933

Last edited by iwtbf; 08-07-2017 at 05:26 PM.
 
Old 08-07-2017, 05:36 PM   #2
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918
If you fancy using a GUI approach, then pyRenamer is a cool utility.

In this case, you would select the pattern of {X}? replaced by {1}.

That deletes all characters in selected filenames after the question mark, including the question mark, so would cover both oggs and mp3s. Note that as it is, it only deletes everything after the ultimate question mark in the filename, but unless you're expecting to find multiple question marks in filenames you should be fine.
 
Old 08-07-2017, 05:41 PM   #3
TheEzekielProject
Member
 
Registered: Dec 2016
Distribution: arch
Posts: 664

Rep: Reputation: 190Reputation: 190
I'm not super experienced with sed but I think you could try something like
Code:
cd /path/to/your/folder
sed -i 's/.mp3*/.mp3/' *
.

I'm sure others will have other suggestions

Last edited by TheEzekielProject; 08-07-2017 at 05:43 PM.
 
Old 08-07-2017, 06:01 PM   #4
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 633

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
You can try using the rename program. -n is "dry-run" mode.
This matches the "?" and everything after and renames it with nothing as demoed below

Code:
$ rename -v -n 's/[?].*//g' 201*
rename(2017-07-12-symhc-bill-berry.mp3?awCollectionId=1002&awEpisodeId=927933, 2017-07-12-symhc-bill-berry.mp3)
rename(2018-07-12-symhc-bill-berry.mp3?awCollectionId=1002&awEpisodeId=927933, 2018-07-12-symhc-bill-berry.mp3)

Last edited by Sefyir; 08-07-2017 at 06:07 PM.
 
1 members found this post helpful.
Old 08-07-2017, 06:12 PM   #5
iwtbf
Member
 
Registered: Apr 2009
Location: cybernetic space
Distribution: debian
Posts: 42

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by Sefyir View Post
You can try using the rename program. -n is "dry-run" mode.
This matches the "?" and everything after and renames it with nothing as demoed below

Code:
$ rename -v -n 's/[?].*//g' 201*
rename(2017-07-12-symhc-bill-berry.mp3?awCollectionId=1002&awEpisodeId=927933, 2017-07-12-symhc-bill-berry.mp3)
rename(2018-07-12-symhc-bill-berry.mp3?awCollectionId=1002&awEpisodeId=927933, 2018-07-12-symhc-bill-berry.mp3)

Thank you so much, it worked like a charm. Highly appreciated!
 
  


Reply

Tags
bash


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
Update/Rename filename sudkool Linux - Newbie 4 05-13-2009 05:38 PM
mp3 filename to xml shell script jason7 Linux - Server 1 03-21-2009 05:22 AM
Convert static library (Filename.a) to dynamic shared object (filename.so) afx2029 Linux - Software 4 08-17-2007 06:07 AM
Filename rename jarod_123 Programming 4 03-21-2006 02:40 PM
Id3 tagging from mp3's filename and folder kzar Linux - General 3 08-22-2004 09:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:17 AM.

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
Open Source Consulting | Domain Registration