Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > rename files problem

Reply
Thread Tools

rename files problem

 
 
hpy_awad@yahoo.com
Guest
Posts: n/a
 
      05-23-2004
I have some files I want to rename them upon parts of their names .
For example : files :
part03_iti_r01_ch03_ver03_conditional_statements_o ne_if_TV_Rental_bills.c
part03_iti_r01_ch03_ver04_conditional_statements_o ne_if_else_TV_Rental_bills.c
part03_iti_r01_ch03_ver05_conditional_statements_m ulti_if_else_TV_Rental_bills.c
part03_iti_r01_ch03_ver06_conditional_statements_s witch_TV_Rental_bills.c


I want to issue unix2dos command for each file :
as:


unix2dos part03_iti_r01_ch03_ver03_conditional_statements_o ne_if_TV_Rental_bills.c
ex0303.c
I will convert
part03_iti_r01_ch03_ver03_conditional_statements_o ne_if_TV_Rental_bills.c
I chose ex^^ & ^^.c

Which utility I can choose for accomplishing thar task ?
sed,Perl.... How can I use it in a loop?
 
Reply With Quote
 
 
 
 
William Park
Guest
Posts: n/a
 
      05-23-2004
In <comp.unix.shell> http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> wrote:
> I have some files I want to rename them upon parts of their names .
> For example : files :
> part03_iti_r01_ch03_ver03_conditional_statements_o ne_if_TV_Rental_bills.c
> part03_iti_r01_ch03_ver04_conditional_statements_o ne_if_else_TV_Rental_bills.c
> part03_iti_r01_ch03_ver05_conditional_statements_m ulti_if_else_TV_Rental_bills.c
> part03_iti_r01_ch03_ver06_conditional_statements_s witch_TV_Rental_bills.c
>
>
> I want to issue unix2dos command for each file :
> as:
>
>
> unix2dos part03_iti_r01_ch03_ver03_conditional_statements_o ne_if_TV_Rental_bills.c
> ex0303.c
> I will convert
> part03_iti_r01_ch03_ver03_conditional_statements_o ne_if_TV_Rental_bills.c
> I chose ex^^ & ^^.c
>
> Which utility I can choose for accomplishing thar task ?
> sed,Perl.... How can I use it in a loop?


Hint:
sed 's/.*_ch\([0-9][0-9]\)_ver\([0-9][0-9]\).*/ex\1\2/'

while IFS='_' read part iti r ch ver rest; do
echo $ch $ver
echo ${ch#ch} ${ver#ver}
done

--
William Park, Open Geometry Consulting, <(E-Mail Removed)>
Linux solution/training/migration, Thin-client
 
Reply With Quote
 
 
 
 
Michele Dondi
Guest
Posts: n/a
 
      05-24-2004
On 23 May 2004 12:10:15 -0700, (E-Mail Removed)
((E-Mail Removed)) wrote:

>I have some files I want to rename them upon parts of their names .
>For example : files :
>part03_iti_r01_ch03_ver03_conditional_statements_ one_if_TV_Rental_bills.c
>part03_iti_r01_ch03_ver04_conditional_statements_ one_if_else_TV_Rental_bills.c
>part03_iti_r01_ch03_ver05_conditional_statements_ multi_if_else_TV_Rental_bills.c
>part03_iti_r01_ch03_ver06_conditional_statements_ switch_TV_Rental_bills.c

[snip]
>I will convert
>part03_iti_r01_ch03_ver03_conditional_statements_ one_if_TV_Rental_bills.c
>I chose ex^^ & ^^.c
>
>Which utility I can choose for accomplishing thar task ?
>sed,Perl.... How can I use it in a loop?


If your filenames are *really* that regular, then you may use
something like

# ls *.c
[snip list as above]

# perl -e '$"=""; rename $_, "ex@{[(/\d+/g)[2,3]]}.c" for @ARGV' *.c
# ls *.c
ex0303.c ex0304.c ex0305.c ex0306.c


Michele
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do you rename files with long names? murphdrag Computer Support 6 02-13-2005 11:26 PM
Rename file names at once (200 files) Adi Computer Support 1 09-09-2004 05:16 PM
Software to rename alot of files traxxton Computer Support 5 07-08-2004 01:39 PM
Does anyone know of a program to rename multiple files? James Haddow Computer Support 7 11-27-2003 09:51 PM
Re: how to delete or rename files within nero Shepİ Computer Support 0 07-04-2003 08:33 PM



Advertisments