Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

sed - removing/renaming file extensions.

Options
  • 28-06-2005 5:57pm
    #1
    Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 91,758 Mod ✭✭✭✭


    I want to copy files into a folder, but if a file of the name already exists I want to rename one of them so I get Filename_X.EXT where X is the next number.

    I can remove file extensions by
    dir | sed s\...$\\ but I need to use the extension later on too.

    Should I be able to use sed h.....$ to store the extension and then append it later ?


    I could use sed to reverse the string, then use FOR (Windows command line) to remove everything up to the first dot and then use sed to reverse the three characters, but that would just be stupid if there is an easier way.

    I could also just process one file type at a time, but would rather a generic way.

    sed scripts I've looked at
    http://sed.sourceforge.net/sed1line.txt
    http://www.student.northpark.edu/pemente/sed/sedfaq.html


Advertisement