Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, I`m knew to this forum , hope you guys out there can find solutions to my Kubuntu setup. The thread starter says mostly what I need but I`ll go ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Jan 2012
    Location
    Earth
    Posts
    103

    922 files need 0001 - taken out of the title; How ?


    Hi,

    I`m knew to this forum , hope you guys out there can find solutions to my Kubuntu setup.

    The thread starter says mostly what I need but I`ll go into it abit more.

    - 922 files - name examples :
    - 0002 - Ticket to America1-001.mpg
    - 0011 - Ticket to America2-014.mpg
    - 0032 - Racing the Wind 1- 001.wmv
    - 0054 - Racing the Wind 2- 008.wmv

    OK. So , what I want to do is delete the "0002 -", part of the file name on all 922 files.

    Yes, i could go through the archive and delete the parts one by one but I`d get tendonitis.

    A solution would bring considerable brain relief.

    Thanks.

  2. #2
    Linux User zenwalker's Avatar
    Join Date
    Feb 2010
    Location
    Inland Empire
    Posts
    292
    Look into PERL

  3. #3
    Linux Newbie
    Join Date
    Jan 2012
    Location
    Earth
    Posts
    103
    Ok, thanks , I`ve just looked at it but don`t see a solucion there. It`s not just a dozen or so files it`s a mega archive.

    The "0001 , 0014, 0054" etc need removing , the rest of the name and ext stays the same.

  4. #4
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,286
    Hi.

    The rename utility allows perl statements to be used to configure how the resulting filename should look. For example:
    Code:
    #!/usr/bin/env bash
    
    # @(#) s1	Demonstrate rename files with perl-pattern utility "rename".
    
    # Utility functions: print-as-echo, print-line-with-visual-space, debug.
    # export PATH="/usr/local/bin:/usr/bin:/bin"
    pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
    pl() { pe;pe "-----" ;pe "$*"; }
    db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
    db() { : ; }
    C=$HOME/bin/context && [ -f $C ] && $C
    
    pl " Local file example set:"
    ls -lgG 0*
    
    pl " Results:"
    rename --no-act 's/^\d* - //' 0*
    
    exit 0
    producing:
    Code:
    % ./s1
    
    Environment: LC_ALL = C, LANG = C
    (Versions displayed with local utility "version")
    OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
    Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
    GNU bash 3.2.39
    
    -----
     Local file example set:
    -rw-r----- 1 0 Jan 30 06:20 0002 - Ticket to America1-001.mpg
    -rw-r----- 1 0 Jan 30 06:20 0011 - Ticket to America2-014.mpg
    -rw-r----- 1 0 Jan 30 06:20 0032 - Racing the Wind 1- 001.wmv
    -rw-r----- 1 0 Jan 30 06:20 0054 - Racing the Wind 2- 008.wmv
    
    -----
     Results:
    0002 - Ticket to America1-001.mpg renamed as Ticket to America1-001.mpg
    0011 - Ticket to America2-014.mpg renamed as Ticket to America2-014.mpg
    0032 - Racing the Wind 1- 001.wmv renamed as Racing the Wind 1- 001.wmv
    0054 - Racing the Wind 2- 008.wmv renamed as Racing the Wind 2- 008.wmv
    Things to note:
    1) "s'" means substitute: the part of the string to be deleted is "start-of-name digits space dash space"
    2) the "--no-act" shows what will be done

    See man rename for details ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  5. #5
    Linux Newbie
    Join Date
    Jan 2012
    Location
    Earth
    Posts
    103
    Thanks for taking the time to post your cryptic answer. i have re-ordered all the files and put them in folders.

    Thanks again for your solutions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •