#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    4
    Rep Power
    0

    Question Changing file extension





    Guys -
    I wanna move files with "*.doc" extn to "*.txt ".
    Is there any command in unix to do that? or we have to go for shell script?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    13
    rename s/\.txt/.doc/ *.txt

    Or if you want to use a more sophisticated regex to avoid documents like this-has-a-.txt-that-is-not-the-extension.txt being changed into this-has-a-.doc-that-is-not-the-extension.txt
    then that's fine as well. But that's an okay regex for 95% of the cases.

    Oh, also, this isn't a "standard Unix(TM) command, but it does come with most Perl installations that I know of and Perl is on most Unix machines that I know of.
    Debian - because life's too short for worrying.
    Best. (Python.) IRC bot. ever.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    4
    Rep Power
    0
    Hey - Thanks for reply...
    Can you pls make it on Shell script?

    In my system perl is installed ...but i dunno how to execute this cmd...when i type this command it is thrwoing syntax error
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    Code:
    for i in *.txt; do mv "$i" `basename $i`.doc; done
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    4
    Rep Power
    0

    Thumbs up


    It works ..thanks you guys ....

IMN logo majestic logo threadwatch logo seochat tools logo