Sponsored Content
Full Discussion: Bash: renaming file issues.
Top Forums Shell Programming and Scripting Bash: renaming file issues. Post 302599849 by josco1982 on Sunday 19th of February 2012 12:17:37 AM
Old 02-19-2012
Bash: renaming file issues.

Hi, i want to rename a group of directories and files of my music, some items are like this:

[Artist] - [Album], for directories.
[Artist] - [Song title], for files.

I want to do something like this:

[Album], for directories.
[Song title], for files.

This is my code:
Code:
#!/bin/bash
for fname in *.mp3; do
    echo item: $fname
    mv -f $fname ${fname#*-}
done

This is a reduced list of my output:
Code:
user@intel-computer:~/Music/tmp$ ./trim_filename.sh
item: 01 - Bad Romance.mp3
mv: target `Romance.mp3' is not a directory
item: 01 - Just Dance.mp3
mv: target `Dance.mp3' is not a directory
item: 02 - Alejandro.mp3
mv: target `Alejandro.mp3' is not a directory
item: 02 - LoveGame.mp3
mv: target `LoveGame.mp3' is not a directory
item: 03 - Paparazzi.mp3
mv: target `Paparazzi.mp3' is not a directory
item: 04 - Poker Face.mp3
mv: target `Face.mp3' is not a directory
item: 05 - Dance In the Dark.mp3
mv: target `Dark.mp3' is not a directory
item: 06 - Telephone.mp3
mv: target `Telephone.mp3' is not a directory
user@intel-computer:~/Music/tmp$

Can anyone throw some pointers for this?
Thank you for your kind attention.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming files in a bash script

I'm doing a short batch script to compile po files producing output binary mo files. The compilation command is: msgfmt -o file.mo file.po so in order to compile I am appending .mo to the varible in a loop. It goes something like this: for i in `find . -name "*.po"` do echo... (2 Replies)
Discussion started by: Breen
2 Replies

2. Shell Programming and Scripting

Bash script issues

Hi. The below part of my bash script kicks out the following error message: $ ./extract_eod_report_stats_new.sh 2010-04-23 ./extract_eod_report_stats_new.sh: line 204: syntax error near unexpected token `(' ./extract_eod_report_stats_new.sh: line 204: `TRANSACTIONS_RECEIVED_TOP=`grep... (6 Replies)
Discussion started by: Peter.Lovell
6 Replies

3. Shell Programming and Scripting

Bash Script issues

So what i am trying to do is write a script that takes in any number of scrambeled words and unscrambles them. I have already addressed the issues of partial matches, exits silently if there are no matches, and finds words regardless of case that they were input. but while trying to get it so... (3 Replies)
Discussion started by: alindner
3 Replies

4. Shell Programming and Scripting

BASH Batch renaming insert additional zero into filename

Hi all, Wondering how this could be accomplished........ a directory contains sequentially numbered files from fw01 to fw999. How would I insert an additional zero so that the directory lists these files in a proper manner? (i.e. all double digit files from fw01 to fw99 would become... (3 Replies)
Discussion started by: putter1900
3 Replies

5. Shell Programming and Scripting

Unix bash script (mv issues);

Hey guys, I've registered here as I need urgent help. This is assignment for school and as you can see below I've completed the work. I'm simply stuck on one area. :wall: This script takes the first parameter (which is to be the new extension) and each parameter after that is a file... (1 Reply)
Discussion started by: Cynosure
1 Replies

6. Shell Programming and Scripting

Bash Script Issues (If statement for file copying)

Writing a bash script for use with Geektool, pulls the battery info, and shuffles images around so that an Image geeklet can display the correct expression as the desktop background. (Eventually I intend to make it more intricate, based on more variables, and add more expressions) I'm extremely... (1 Reply)
Discussion started by: The_Ardly374
1 Replies

7. Shell Programming and Scripting

Bash Case Issues..

Hi, I'm having some trouble with using "case...esac" in Bash. I've googled it and am stuggling to understand the syntax and how to do certain things. Firstly, I want to be able to choose a case based on a variable number For example, I have in my code a place where a user can enter... (2 Replies)
Discussion started by: Ste_Moore01
2 Replies

8. Shell Programming and Scripting

Bash/cron issues

Hi all, I am trying to run a cronjob to push my files to my git repo once a week and output a prompt to a logfile, my script works fine if I invoke it manually but my cronjob wont run for some reason, I have sourced the file, and restarted my Mac to no avail, right now I believe I have the cronjob... (8 Replies)
Discussion started by: gmenfan83
8 Replies

9. Shell Programming and Scripting

Recursive File Renaming & Natural Sorting (Bash)

NB! I have already started a thread on this subject on ComputerHope (with the thread title "Recursive File Renaming & Logical Sorting"). However, on ComputerHope they are perhaps more specialized in Windows Command Prompt, and not that much in shell scripts for Bash (I guess). I have a bulk... (1 Reply)
Discussion started by: JewzeyfGhewbelz
1 Replies

10. Shell Programming and Scripting

Need help in batch renaming files with bash shell script.

I have some 50+ files in the following format : abcd_vish_running_ZEBRA_20140818.dat_08-14-2014_23:08:23 abcd_vish_running_ZEB-RA_20140818.dat_08-14-2014_23:08:35 abcd_vish_running_ZEB_RA_20140818.dat_08-14-2014_23:08:37 abcd_vish_running_RI-NG_20140818.dat_08-14-2014_23:08:42... (5 Replies)
Discussion started by: SriRamKrish
5 Replies
MP3::Tag::ID3v1(3pm)					User Contributed Perl Documentation				      MP3::Tag::ID3v1(3pm)

NAME
MP3::Tag::ID3v1 - Module for reading / writing ID3v1 tags of MP3 audio files SYNOPSIS
MP3::Tag::ID3v1 is designed to be called from the MP3::Tag module. use MP3::Tag; $mp3 = MP3::Tag->new($filename); # read an existing tag $mp3->get_tags(); $id3v1 = $mp3->{ID3v1} if exists $mp3->{ID3v1}; # or create a new tag $id3v1 = $mp3->new_tag("ID3v1"); See MP3::Tag for information on the above used functions. * Reading the tag print " Title: " .$id3v1->title . " "; print " Artist: " .$id3v1->artist . " "; print " Album: " .$id3v1->album . " "; print "Comment: " .$id3v1->comment . " "; print " Year: " .$id3v1->year . " "; print " Genre: " .$id3v1->genre . " "; print " Track: " .$id3v1->track . " "; # or at once @tagdata = $mp3->all(); foreach $tag (@tagdata) { print $tag; } * Changing / Writing the tag $id3v1->comment("This is only a Test Tag"); $id3v1->title("testing"); $id3v1->artist("Artest"); $id3v1->album("Test it"); $id3v1->year("1965"); $id3v1->track("5"); $id3v1->genre("Blues"); # or at once $id3v1->all("song title","artist","album","1900","comment",10,"Ska"); $id3v1->write_tag(); * Removing the tag from the file $id3v1->remove_tag(); AUTHOR
Thomas Geffert, thg@users.sourceforge.net DESCRIPTION
title(), artist(), album(), year(), comment(), track(), genre() $artist = $id3v1->artist; $artist = $id3v1->artist($artist); $album = $id3v1->album; $album = $id3v1->album($album); $year = $id3v1->year; $year = $id3v1->year($year); $comment = $id3v1->comment; $comment = $id3v1->comment($comment); $track = $id3v1->track; $track = $id3v1->track($track); $genre = $id3v1->genre; $genre = $id3v1->genre($genre); Use these functions to retrieve the date of these fields, or to set the data. $genre can be a string with the name of the genre, or a number describing the genre. all() @tagdata = $id3v1->all; @tagdata = $id3v1->all($title, $artist, $album, $year, $comment, $track, $genre); Returns all information of the tag in a list. You can use this sub also to set the data of the complete tag. The order of the data is always title, artist, album, year, comment, track, and genre. genre has to be a string with the name of the genre, or a number identifying the genre. fits_tag() warn "data truncated" unless $id3v1->fits_tag($hash); Check whether the info in ID3v1 tag fits into the format of the file. as_bin() $str = $id3v1->as_bin(); Returns the ID3v1 tag as a string. write_tag() $id3v1->write_tag(); [old name: writeTag() . The old name is still available, but you should use the new name] Writes the ID3v1 tag to the file. remove_tag() $id3v1->remove_tag(); Removes the ID3v1 tag from the file. Returns negative on failure, FALSE if no tag was found. (Caveat: only one tag is removed; some - broken - files may have many chain-loaded one after another; you may need to call remove_tag() in a loop to handle such beasts.) [old name: removeTag() . The old name is still available, but you should use the new name] genres() @allgenres = $id3v1->genres; $genreName = $id3v1->genres($genreID); $genreID = $id3v1->genres($genreName); Returns a list of all genres, or the according name or id to a given id or name. new() $id3v1 = MP3::Tag::ID3v1->new($mp3fileobj[, $create]); Generally called from MP3::Tag, because a $mp3fileobj is needed. If $create is true, a new tag is created. Otherwise undef is returned, if now ID3v1 tag is found in the $mp3obj. Please use $mp3 = MP3::Tag->new($filename); $id3v1 = $mp3->new_tag("ID3v1"); # Empty new tag or $mp3 = MP3::Tag->new($filename); $mp3->get_tags(); $id3v1 = $mp3->{ID3v1}; # Existing tag (if present) instead of using this function directly SEE ALSO
MP3::Tag, MP3::Tag::ID3v2 ID3v1 standard - http://www.id3.org COPYRIGHT
Copyright (c) 2000-2004 Thomas Geffert. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License, distributed with Perl. perl v5.14.2 2009-11-28 MP3::Tag::ID3v1(3pm)
All times are GMT -4. The time now is 01:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy