Home > Archive > Unix Programming > May 2004 > rename files problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
rename files problem
|
|
| hpy_awad@yahoo.com 2004-05-23, 4:36 pm |
| I have some files I want to rename them upon parts of their names .
For example : files :
part03_iti_r01_ch03_ver03_conditional_st
atements_one_if_TV_Rental_bills.c
part03_iti_r01_ch03_ver04_conditional_st
atements_one_if_else_TV_Rental_bills.c
part03_iti_r01_ch03_ver05_conditional_st
atements_multi_if_else_TV_Rental_bills.c
part03_iti_r01_ch03_ver06_conditional_st
atements_switch_TV_Rental_bills.c
I want to issue unix2dos command for each file :
as:
unix2dos part03_iti_r01_ch03_ver03_conditional_st
atements_one_if_TV_Rental_bills.c
ex0303.c
I will convert
part03_iti_r01_ch03_ver03_conditional_st
atements_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?
| |
| William Park 2004-05-23, 8:31 pm |
| In <comp.unix.shell> hpy_awad@yahoo.com <ehab_aziz2001@yahoo.com> wrote:
> I have some files I want to rename them upon parts of their names .
> For example : files :
> part03_iti_r01_ch03_ver03_conditional_st
atements_one_if_TV_Rental_bills.c
> part03_iti_r01_ch03_ver04_conditional_st
atements_one_if_else_TV_Rental_bills.c
> part03_iti_r01_ch03_ver05_conditional_st
atements_multi_if_else_TV_Rental_bills.c
> part03_iti_r01_ch03_ver06_conditional_st
atements_switch_TV_Rental_bills.c
>
>
> I want to issue unix2dos command for each file :
> as:
>
>
> unix2dos part03_iti_r01_ch03_ver03_conditional_st
atements_one_if_TV_Rental_bills.c
> ex0303.c
> I will convert
> part03_iti_r01_ch03_ver03_conditional_st
atements_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?
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, <opengeometry@yahoo.ca>
Linux solution/training/migration, Thin-client
| |
| Michele Dondi 2004-05-24, 9:41 am |
| On 23 May 2004 12:10:15 -0700, ehab_aziz2001@yahoo.com
(hpy_awad@yahoo.com) wrote:
>I have some files I want to rename them upon parts of their names .
>For example : files :
> part03_iti_r01_ch03_ver03_conditional_st
atements_one_if_TV_Rental_bills.c
> part03_iti_r01_ch03_ver04_conditional_st
atements_one_if_else_TV_Rental_bills.c
> part03_iti_r01_ch03_ver05_conditional_st
atements_multi_if_else_TV_Rental_bills.c
> part03_iti_r01_ch03_ver06_conditional_st
atements_switch_TV_Rental_bills.c
[snip]
>I will convert
> part03_iti_r01_ch03_ver03_conditional_st
atements_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"
|
|
|
|
|