LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 04-04-2012, 10:48 AM   #1
kgoerbig
LQ Newbie
 
Registered: Apr 2006
Posts: 3

Rep: Reputation: 0
SED - Need help removing characyers from filenames


I have hundreds of .zip N64 games. I want to remove certain characters from the filenames, but I'm terrible wihth SED and regular expressions. The files look like this:

Paperboy (U) [!].zip
Paper Mario (U) [!].zip
Penny Racers (U) [!].zip
Perfect Dark (U) (V1.1) [!].zip
PGAeurotour.zip
Pilotwings64.zip
Pokemon Puzzle League (U) [!].zip
Pokemon Snap Station (U) [!].zip
Pokemon Snap (U) [!].zip
Pokemon Stadium 2 (U) [!].zip
Pokemon Stadium (U) (V1.1) [!].zip
Polaris SnoCross (U) [!].zip
Powerpuff Girls, The - Chemical X-Traction (U) [!].zip
Power Rangers - Lightspeed Rescue (U) [!].zip
Premier Manager 64 (E) [!].zip

I want to remove every instance of these characters from every filename, and remove the spaces.

(U) [!] (E) (V1.1)

Any help would be appreciated.

Last edited by kgoerbig; 04-04-2012 at 10:49 AM.
 
Old 04-04-2012, 12:16 PM   #2
uhelp
Member
 
Registered: Nov 2011
Location: Germany, Bavaria, Nueremberg area
Distribution: openSUSE, Debian, LFS
Posts: 205

Rep: Reputation: 43
Code:
for file in * ; do       # will act on all files in the working dir
    temp=${file%%(*}        #get everthing up to the first "("
    temp2=${temp//' '/_}    # translate spaces to "_"  ; adjust to youre needs
    mv "$file" "${temp2}.zip"     # and rename the file
done
It does not test, whether it is a ".zip"
It only assumes this.
 
Old 04-04-2012, 12:37 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
Easy enough to insure .zip by adding to the wildcard in the for loop:
Code:
for file in *.zip ; do
Also, no need for the quotes around the space in the underscore translation.

As a precaution to test the script, simply place an echo prior to mv and you will see a print out of what will happen once removed
 
  


Reply



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
How do you remove Parenthesis from filenames using sed xmrkite Linux - Software 11 06-09-2010 03:30 PM
Removing charaacters from multiple filenames old-n-crazy Linux - Software 3 03-20-2009 04:45 PM
Removing special characters from filenames PlymWS Linux - Software 1 08-09-2007 05:11 AM
Bash Renaming (removing a string from filenames) FreeDoughnut Programming 9 07-20-2006 09:54 PM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM

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

All times are GMT -5. The time now is 09:15 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