rename files problem

Discussion in 'Perl Misc' started by hpy_awad@yahoo.com, May 23, 2004.

  1. Guest

    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


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


    unix2dos part03_iti_r01_ch03_ver03_conditional_statements_one_if_TV_Rental_bills.c
    ex0303.c
    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?
     
    , May 23, 2004
    #1
    1. Advertising

  2. William Park Guest

    In <comp.unix.shell> <> 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
    >
    >
    > I want to issue unix2dos command for each file :
    > as:
    >
    >
    > unix2dos part03_iti_r01_ch03_ver03_conditional_statements_one_if_TV_Rental_bills.c
    > ex0303.c
    > 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?


    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, <>
    Linux solution/training/migration, Thin-client
     
    William Park, May 24, 2004
    #2
    1. Advertising

  3. On 23 May 2004 12:10:15 -0700,
    () 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"
     
    Michele Dondi, May 24, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    15
    Views:
    619
    Dudu Figueiredo
    Nov 18, 2005
  2. =?iso-8859-1?b?cultaQ==?=

    Rename multiple files using names in a text file

    =?iso-8859-1?b?cultaQ==?=, Sep 14, 2007, in forum: Python
    Replies:
    2
    Views:
    466
    =?iso-8859-1?b?cultaQ==?=
    Sep 15, 2007
  3. Jeremy
    Replies:
    0
    Views:
    344
    Jeremy
    Feb 18, 2008
  4. Gilles Ganault
    Replies:
    2
    Views:
    263
    Gilles Ganault
    Apr 8, 2011
  5. carrzkiss
    Replies:
    0
    Views:
    446
    carrzkiss
    Jan 15, 2009
Loading...

Share This Page