LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 11-26-2005, 01:44 PM   #1
linuxhippy
Senior Member
 
Registered: Sep 2004
Location: Philadelphia, PA
Distribution: Xubuntu, Mythbuntu, Lubuntu, Picuntu, Mint 18.1, Debian Jessie
Posts: 1,207

Rep: Reputation: 47
renaming multiple files


I have 1191 html files in a directory that I can use fine on an ext3 file system. When I try to copy them onto a vfat USB drive, they will only copy if I remove the ? in each filename. Each file is named like this:


index.html?book_id=26&chapter=5&version=50
index.html?book_id=26&chapter=6&version=50
index.html?book_id=26&chapter=7&version=50
index.html?book_id=26&chapter=8&version=50
index.html?book_id=30&chapter=32&version=50
index.html?book_id=30&chapter=33&version=50
index.html?book_id=30&chapter=34&version=50
.....

I tried:

mv index.html?book_id* /home/huntz/NKJV2/book_id*

and got an error about moving multiple files must go into a specific directory.

So, does a script need to be written for this? If so, what would the script contain to rename files?

Marty

Last edited by linuxhippy; 11-26-2005 at 01:46 PM.
 
Old 11-26-2005, 02:06 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,642

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
Try :
Code:
find . -name "*index.html*" | while read file; do
    book_id=$(echo "$file" | cut -d= -f2 | cut -d'&' -f1)
    chapter=$(echo "$file" | cut -d= -f3 | cut -d'&' -f1)
    mv "$file" "/home/huntz/NKJV2/book_id${book_id}_chapter${chapter}"
done
 
1 members found this post helpful.
Old 11-26-2005, 02:31 PM   #3
egag
Senior Member
 
Registered: Jul 2004
Location: Netherlands
Distribution: Slackware
Posts: 2,721

Rep: Reputation: 53
or :

rename index.html?book book *

btw: there's an error in rename manpage.
where to sent report ?

egag
 
1 members found this post helpful.
Old 11-26-2005, 09:31 PM   #4
linuxhippy
Senior Member
 
Registered: Sep 2004
Location: Philadelphia, PA
Distribution: Xubuntu, Mythbuntu, Lubuntu, Picuntu, Mint 18.1, Debian Jessie
Posts: 1,207

Original Poster
Rep: Reputation: 47
worked like a charm (rename and the script)-thanks!

Last edited by linuxhippy; 11-26-2005 at 10:15 PM.
 
Old 11-26-2005, 09:46 PM   #5
linuxhippy
Senior Member
 
Registered: Sep 2004
Location: Philadelphia, PA
Distribution: Xubuntu, Mythbuntu, Lubuntu, Picuntu, Mint 18.1, Debian Jessie
Posts: 1,207

Original Poster
Rep: Reputation: 47
that rename command is nice-I see how the man page has an error, though. Since Win needes .html on files to open them in a web browser I'd like to add the .html extension on all the files. Currently I have 1191 files with these filenames:


book_id=7&chapter=19&book_id=10&chapter=10&version=50
book_id=7&chapter=1&book_id=10&chapter=10&version=50
book_id=7&chapter=20&book_id=10&chapter=10&version=50
book_id=7&chapter=21&book_id=10&chapter=10&version=50
book_id=7&chapter=2&book_id=10&chapter=10&version=50
book_id=7&chapter=3&book_id=10&chapter=10&version=50
.....

Can I use rename for this?
 
Old 11-27-2005, 01:02 AM   #6
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
There's also a program called "mmv" that can move or copy multiple files.
 
Old 11-27-2005, 10:24 AM   #7
egag
Senior Member
 
Registered: Jul 2004
Location: Netherlands
Distribution: Slackware
Posts: 2,721

Rep: Reputation: 53
Quote:
Originally posted by linuxhippy
that rename command is nice-I see how the man page has an error, though. Since Win needes .html on files to open them in a web browser I'd like to add the .html extension on all the files. Currently I have 1191 files with these filenames:


book_id=7&chapter=19&book_id=10&chapter=10&version=50
book_id=7&chapter=1&book_id=10&chapter=10&version=50
book_id=7&chapter=20&book_id=10&chapter=10&version=50
book_id=7&chapter=21&book_id=10&chapter=10&version=50
book_id=7&chapter=2&book_id=10&chapter=10&version=50
book_id=7&chapter=3&book_id=10&chapter=10&version=50
.....

Can I use rename for this?
yip, but i thought you figured out howto

it's like search&replace:

rename <search -for> <replace-with> <target-files>

here that could be ( can be alot of ways ):

rename version=50 version=50.html *
( assumed the files are all " version=50 " )

egag
 
Old 01-20-2011, 06:41 PM   #8
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 531

Rep: Reputation: 168Reputation: 168
missing mmv

Quote:
Originally Posted by spooon View Post
There's also a program called "mmv" that can move or copy multiple files.
A few minutes ago I was browsing the rename man page, and in the SEE ALSO section it listed mmv. Never heard of it before, and it isn't installed on Slackware 13.1. Should it be?
 
Old 01-20-2011, 07:03 PM   #9
GazL
LQ Veteran
 
Registered: May 2008
Posts: 7,071

Rep: Reputation: 5220Reputation: 5220Reputation: 5220Reputation: 5220Reputation: 5220Reputation: 5220Reputation: 5220Reputation: 5220Reputation: 5220Reputation: 5220Reputation: 5220
It's in a separate package on Fedora too which also isn't installed by default, so I guess the answer is 'no'. I hadn't heard of mmv either.
 
1 members found this post helpful.
Old 01-21-2011, 02:28 AM   #10
acummings
Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 615

Rep: Reputation: 50
Code:
al@P5Q:~/temp/tst$ ls
nam?me1  nam?me2  nam?me3
al@P5Q:~/temp/tst$ find . -type f -name '*?*' -print0 | xargs -0 rename '?' ''
al@P5Q:~/temp/tst$ ls
namme1  namme2  namme3
al@P5Q:~/temp/tst$ find . -type f -name '*mm*' -print0 | xargs -0 rename 'mm' 'm?m' ''
al@P5Q:~/temp/tst$ ls
nam?me1  nam?me2  nam?me3
al@P5Q:~/temp/tst$ find . -type f -name '*?*' -print0 | xargs -0 rename '?' '_' ''
al@P5Q:~/temp/tst$ ls
nam_me1  nam_me2  nam_me3
al@P5Q:~/temp/tst$
--
Alan
 
Old 01-21-2011, 02:53 AM   #11
acummings
Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 615

Rep: Reputation: 50
Oop, O onadvertently had an extra set of unneeded single quotes at the very RH end of the one liner.

Code:
al@P5Q:~/temp/tst$ ls
nam?me1  nam?me2  nam?me3
al@P5Q:~/temp/tst$ find . -type f -name '*?*' -print0 | xargs -0 rename '?' '_' ''
al@P5Q:~/temp/tst$ ls
nam_me1  nam_me2  nam_me3
al@P5Q:~/temp/tst$
So, the corrected would be:
Code:
al@P5Q:~/temp/tst$ ls
nam?me1  nam?me2  nam?me3
al@P5Q:~/temp/tst$ find . -type f -name '*?*' -print0 | xargs -0 rename '?' '_'
al@P5Q:~/temp/tst$ ls
nam_me1  nam_me2  nam_me3
al@P5Q:~/temp/tst$
Only 2 args to the rename ie swap ? with _ in that above case

I found it from here:

http://linux.derkeiler.com/Mailing-L.../msg02549.html

It's powerful on my box and it worked even, despite that I had a mistake in the one liner.

--
Alan.
 
  


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
renaming multiple files in general kkatebian Linux - General 5 11-06-2005 12:05 PM
Renaming Multiple Files with a "." on the end of the filename dbowles Programming 1 05-09-2005 05:28 PM
Need help with shell script - renaming multiple files NiallC Linux - Newbie 25 07-04-2004 11:45 AM
Renaming multiple files with the same format Shr00mBoXx Slackware 7 06-20-2004 08:22 PM
Solution: renaming multiple files with spaces HawkeyeCoug Linux - Newbie 0 03-26-2004 11:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 10:53 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
Open Source Consulting | Domain Registration