Change part of the filename on multiple files in a directory:











up vote
2
down vote

favorite












I once had a script that would do the following. It would rename part of a filename of multiple files in the current directory:



For example:



rename variable1 variable2

rename 456 555


Input:



testa456testa
sama456sama
apple456applea
johna_456_johna
davida_456_davidb


Output:



testa555testa
sama555sama
apple555applea
johna_555_johna
davida_555_davidb


I don't have the script anymore, and I am still new to Unix.
I need a script, that I can use from the command line.



What I do now is:



I list the files "ls * (file names)" to a temp file name. Then I do a search %/s/456/555/g. Then I move all old file names, to new file names. I was able to do this in a command line "rename $1 to $2". So, in any given directory I would line to rename middle of file names from a command line. It could be hundreds of files. Hope this make sense, Thanks Ivan










share|improve this question




















  • 1




    What's the question? Do you want help writing a script? Finding it? Making use of alternatives? Solving this specific problem of changing 456 to 555? Please edit your text to include a question. And while you're there please tell us your UNIX flavour or Linux distribution.
    – roaima
    Oct 12 '16 at 21:17












  • yes, i need a script that i can used from the command line. I am still new to Unix. What i do is "ls * (file names)" to a temp file name. then do a search %/s/456/555/g. then move all old file names to new file names. I was able to do this in a command line "rename $1 to $2". So, in any given directory i would line to rename middle of file names. It could be hundred of files. Hope this make sense, Thanks.
    – ivan
    Oct 13 '16 at 13:30












  • What UNIX flavour or Linux distribution are you using? Is there any particular reason why you haven't installed the missing rename script?
    – roaima
    Oct 16 '16 at 22:41















up vote
2
down vote

favorite












I once had a script that would do the following. It would rename part of a filename of multiple files in the current directory:



For example:



rename variable1 variable2

rename 456 555


Input:



testa456testa
sama456sama
apple456applea
johna_456_johna
davida_456_davidb


Output:



testa555testa
sama555sama
apple555applea
johna_555_johna
davida_555_davidb


I don't have the script anymore, and I am still new to Unix.
I need a script, that I can use from the command line.



What I do now is:



I list the files "ls * (file names)" to a temp file name. Then I do a search %/s/456/555/g. Then I move all old file names, to new file names. I was able to do this in a command line "rename $1 to $2". So, in any given directory I would line to rename middle of file names from a command line. It could be hundreds of files. Hope this make sense, Thanks Ivan










share|improve this question




















  • 1




    What's the question? Do you want help writing a script? Finding it? Making use of alternatives? Solving this specific problem of changing 456 to 555? Please edit your text to include a question. And while you're there please tell us your UNIX flavour or Linux distribution.
    – roaima
    Oct 12 '16 at 21:17












  • yes, i need a script that i can used from the command line. I am still new to Unix. What i do is "ls * (file names)" to a temp file name. then do a search %/s/456/555/g. then move all old file names to new file names. I was able to do this in a command line "rename $1 to $2". So, in any given directory i would line to rename middle of file names. It could be hundred of files. Hope this make sense, Thanks.
    – ivan
    Oct 13 '16 at 13:30












  • What UNIX flavour or Linux distribution are you using? Is there any particular reason why you haven't installed the missing rename script?
    – roaima
    Oct 16 '16 at 22:41













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I once had a script that would do the following. It would rename part of a filename of multiple files in the current directory:



For example:



rename variable1 variable2

rename 456 555


Input:



testa456testa
sama456sama
apple456applea
johna_456_johna
davida_456_davidb


Output:



testa555testa
sama555sama
apple555applea
johna_555_johna
davida_555_davidb


I don't have the script anymore, and I am still new to Unix.
I need a script, that I can use from the command line.



What I do now is:



I list the files "ls * (file names)" to a temp file name. Then I do a search %/s/456/555/g. Then I move all old file names, to new file names. I was able to do this in a command line "rename $1 to $2". So, in any given directory I would line to rename middle of file names from a command line. It could be hundreds of files. Hope this make sense, Thanks Ivan










share|improve this question















I once had a script that would do the following. It would rename part of a filename of multiple files in the current directory:



For example:



rename variable1 variable2

rename 456 555


Input:



testa456testa
sama456sama
apple456applea
johna_456_johna
davida_456_davidb


Output:



testa555testa
sama555sama
apple555applea
johna_555_johna
davida_555_davidb


I don't have the script anymore, and I am still new to Unix.
I need a script, that I can use from the command line.



What I do now is:



I list the files "ls * (file names)" to a temp file name. Then I do a search %/s/456/555/g. Then I move all old file names, to new file names. I was able to do this in a command line "rename $1 to $2". So, in any given directory I would line to rename middle of file names from a command line. It could be hundreds of files. Hope this make sense, Thanks Ivan







rename






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 at 10:05









Michael Prokopec

72316




72316










asked Oct 12 '16 at 21:06









ivan

23125




23125








  • 1




    What's the question? Do you want help writing a script? Finding it? Making use of alternatives? Solving this specific problem of changing 456 to 555? Please edit your text to include a question. And while you're there please tell us your UNIX flavour or Linux distribution.
    – roaima
    Oct 12 '16 at 21:17












  • yes, i need a script that i can used from the command line. I am still new to Unix. What i do is "ls * (file names)" to a temp file name. then do a search %/s/456/555/g. then move all old file names to new file names. I was able to do this in a command line "rename $1 to $2". So, in any given directory i would line to rename middle of file names. It could be hundred of files. Hope this make sense, Thanks.
    – ivan
    Oct 13 '16 at 13:30












  • What UNIX flavour or Linux distribution are you using? Is there any particular reason why you haven't installed the missing rename script?
    – roaima
    Oct 16 '16 at 22:41














  • 1




    What's the question? Do you want help writing a script? Finding it? Making use of alternatives? Solving this specific problem of changing 456 to 555? Please edit your text to include a question. And while you're there please tell us your UNIX flavour or Linux distribution.
    – roaima
    Oct 12 '16 at 21:17












  • yes, i need a script that i can used from the command line. I am still new to Unix. What i do is "ls * (file names)" to a temp file name. then do a search %/s/456/555/g. then move all old file names to new file names. I was able to do this in a command line "rename $1 to $2". So, in any given directory i would line to rename middle of file names. It could be hundred of files. Hope this make sense, Thanks.
    – ivan
    Oct 13 '16 at 13:30












  • What UNIX flavour or Linux distribution are you using? Is there any particular reason why you haven't installed the missing rename script?
    – roaima
    Oct 16 '16 at 22:41








1




1




What's the question? Do you want help writing a script? Finding it? Making use of alternatives? Solving this specific problem of changing 456 to 555? Please edit your text to include a question. And while you're there please tell us your UNIX flavour or Linux distribution.
– roaima
Oct 12 '16 at 21:17






What's the question? Do you want help writing a script? Finding it? Making use of alternatives? Solving this specific problem of changing 456 to 555? Please edit your text to include a question. And while you're there please tell us your UNIX flavour or Linux distribution.
– roaima
Oct 12 '16 at 21:17














yes, i need a script that i can used from the command line. I am still new to Unix. What i do is "ls * (file names)" to a temp file name. then do a search %/s/456/555/g. then move all old file names to new file names. I was able to do this in a command line "rename $1 to $2". So, in any given directory i would line to rename middle of file names. It could be hundred of files. Hope this make sense, Thanks.
– ivan
Oct 13 '16 at 13:30






yes, i need a script that i can used from the command line. I am still new to Unix. What i do is "ls * (file names)" to a temp file name. then do a search %/s/456/555/g. then move all old file names to new file names. I was able to do this in a command line "rename $1 to $2". So, in any given directory i would line to rename middle of file names. It could be hundred of files. Hope this make sense, Thanks.
– ivan
Oct 13 '16 at 13:30














What UNIX flavour or Linux distribution are you using? Is there any particular reason why you haven't installed the missing rename script?
– roaima
Oct 16 '16 at 22:41




What UNIX flavour or Linux distribution are you using? Is there any particular reason why you haven't installed the missing rename script?
– roaima
Oct 16 '16 at 22:41










4 Answers
4






active

oldest

votes

















up vote
0
down vote













It looks like you're forgetting to pass the files to rename.



rename 456 555 *456*





share|improve this answer





















  • The OP said they no longer had rename, so suggesting they use rename (of any flavour) doesn't seem particularly helpful.
    – roaima
    Oct 12 '16 at 21:26










  • @roaima it sounds like he had a script that used rename and he forgot how to use rename, not that he doesn't have rename at all.
    – Zachary Brady
    Oct 12 '16 at 21:27












  • Mmmm. Not convinced but given the poor question I'll go with that.
    – roaima
    Oct 12 '16 at 21:30


















up vote
0
down vote













With only shell, using parameter expansion:



for f in *456*; do echo mv -i -- "$f" "${f//456/555}"; done


here we re iterating over the files having 456 in their names, and the parameter expansion pattern ${f//456/555} will replace all 456 substrings in the filename with 555.



The above will do the dry-run by showing what mv command will be run, you can remove echo to let the action take place:



for f in *456*; do mv -i -- "$f" "${f//456/555}"; done




With rename (prename):



rename -n 's/456/555/g' *456*


this will replace all (g) 456 substring from filenames with 555 (s/456/555/).



-n will do the dry-run, if you are satisfied with the changes to be made, remove -n to let the actual renaming take place:



rename 's/456/555/g' *456*





share|improve this answer






























    up vote
    0
    down vote













    which -a rename


    Will tell you if any rename tools are on your $PATH.



    rename 's/456/555/g' *


    Is the preferred syntax for doing what you want (As stated in the manual). If you have no or an old version of rename without regex just download (official) prename Which is a perl script debian like systems use.






    share|improve this answer























    • The OP said they no longer had rename, so suggesting they use rename (of any flavour) doesn't seem particularly helpful.
      – roaima
      Oct 12 '16 at 21:26










    • @roaina the OP is using rename wrong resulting in no action. Likely 'which rename' exists. Also if the OP really is missing it I informed him how to get it.
      – user1133275
      Oct 12 '16 at 21:30










    • Mmm ok. Perhaps.
      – roaima
      Oct 12 '16 at 21:35




















    up vote
    0
    down vote













    (Moved from a question intended as an answer here)



    I have found the answer to my question:



    #! /bin/csh -f
    #----------------------------------------------------------------------
    # Script Name: moveme Date: 05/07/96
    # Written by: John W. Woolsey Rev: 10/11/99
    #
    # Description:
    # Renames a set of files that contain a particular search string
    # to file names that contain a replacement string.
    #
    # Syntax: moveme <search_string> <replace_string>
    #
    # Where:
    # <search_string> is the name of the file name search string.
    # <replace_string> is the name of the file name replace string.
    #----------------------------------------------------------------------
    #
    onintr catch
    if ($#argv != 2) goto syntax

    ls -d *$1* | sed "s/(.*)$1(.*)/mv & 1$22/" | sh
    exit 0

    syntax:
    echo "Syntax: `basename $0` <search_string> <replace_string>"
    exit 1

    catch:
    echo "`basename $0` was interrupted or terminated abnormally."
    exit 1





    share|improve this answer























    • Huh, a csh script that generate sh code...
      – Kusalananda
      Jul 28 at 17:28











    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f316038%2fchange-part-of-the-filename-on-multiple-files-in-a-directory%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    It looks like you're forgetting to pass the files to rename.



    rename 456 555 *456*





    share|improve this answer





















    • The OP said they no longer had rename, so suggesting they use rename (of any flavour) doesn't seem particularly helpful.
      – roaima
      Oct 12 '16 at 21:26










    • @roaima it sounds like he had a script that used rename and he forgot how to use rename, not that he doesn't have rename at all.
      – Zachary Brady
      Oct 12 '16 at 21:27












    • Mmmm. Not convinced but given the poor question I'll go with that.
      – roaima
      Oct 12 '16 at 21:30















    up vote
    0
    down vote













    It looks like you're forgetting to pass the files to rename.



    rename 456 555 *456*





    share|improve this answer





















    • The OP said they no longer had rename, so suggesting they use rename (of any flavour) doesn't seem particularly helpful.
      – roaima
      Oct 12 '16 at 21:26










    • @roaima it sounds like he had a script that used rename and he forgot how to use rename, not that he doesn't have rename at all.
      – Zachary Brady
      Oct 12 '16 at 21:27












    • Mmmm. Not convinced but given the poor question I'll go with that.
      – roaima
      Oct 12 '16 at 21:30













    up vote
    0
    down vote










    up vote
    0
    down vote









    It looks like you're forgetting to pass the files to rename.



    rename 456 555 *456*





    share|improve this answer












    It looks like you're forgetting to pass the files to rename.



    rename 456 555 *456*






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Oct 12 '16 at 21:20









    Zachary Brady

    3,396932




    3,396932












    • The OP said they no longer had rename, so suggesting they use rename (of any flavour) doesn't seem particularly helpful.
      – roaima
      Oct 12 '16 at 21:26










    • @roaima it sounds like he had a script that used rename and he forgot how to use rename, not that he doesn't have rename at all.
      – Zachary Brady
      Oct 12 '16 at 21:27












    • Mmmm. Not convinced but given the poor question I'll go with that.
      – roaima
      Oct 12 '16 at 21:30


















    • The OP said they no longer had rename, so suggesting they use rename (of any flavour) doesn't seem particularly helpful.
      – roaima
      Oct 12 '16 at 21:26










    • @roaima it sounds like he had a script that used rename and he forgot how to use rename, not that he doesn't have rename at all.
      – Zachary Brady
      Oct 12 '16 at 21:27












    • Mmmm. Not convinced but given the poor question I'll go with that.
      – roaima
      Oct 12 '16 at 21:30
















    The OP said they no longer had rename, so suggesting they use rename (of any flavour) doesn't seem particularly helpful.
    – roaima
    Oct 12 '16 at 21:26




    The OP said they no longer had rename, so suggesting they use rename (of any flavour) doesn't seem particularly helpful.
    – roaima
    Oct 12 '16 at 21:26












    @roaima it sounds like he had a script that used rename and he forgot how to use rename, not that he doesn't have rename at all.
    – Zachary Brady
    Oct 12 '16 at 21:27






    @roaima it sounds like he had a script that used rename and he forgot how to use rename, not that he doesn't have rename at all.
    – Zachary Brady
    Oct 12 '16 at 21:27














    Mmmm. Not convinced but given the poor question I'll go with that.
    – roaima
    Oct 12 '16 at 21:30




    Mmmm. Not convinced but given the poor question I'll go with that.
    – roaima
    Oct 12 '16 at 21:30












    up vote
    0
    down vote













    With only shell, using parameter expansion:



    for f in *456*; do echo mv -i -- "$f" "${f//456/555}"; done


    here we re iterating over the files having 456 in their names, and the parameter expansion pattern ${f//456/555} will replace all 456 substrings in the filename with 555.



    The above will do the dry-run by showing what mv command will be run, you can remove echo to let the action take place:



    for f in *456*; do mv -i -- "$f" "${f//456/555}"; done




    With rename (prename):



    rename -n 's/456/555/g' *456*


    this will replace all (g) 456 substring from filenames with 555 (s/456/555/).



    -n will do the dry-run, if you are satisfied with the changes to be made, remove -n to let the actual renaming take place:



    rename 's/456/555/g' *456*





    share|improve this answer



























      up vote
      0
      down vote













      With only shell, using parameter expansion:



      for f in *456*; do echo mv -i -- "$f" "${f//456/555}"; done


      here we re iterating over the files having 456 in their names, and the parameter expansion pattern ${f//456/555} will replace all 456 substrings in the filename with 555.



      The above will do the dry-run by showing what mv command will be run, you can remove echo to let the action take place:



      for f in *456*; do mv -i -- "$f" "${f//456/555}"; done




      With rename (prename):



      rename -n 's/456/555/g' *456*


      this will replace all (g) 456 substring from filenames with 555 (s/456/555/).



      -n will do the dry-run, if you are satisfied with the changes to be made, remove -n to let the actual renaming take place:



      rename 's/456/555/g' *456*





      share|improve this answer

























        up vote
        0
        down vote










        up vote
        0
        down vote









        With only shell, using parameter expansion:



        for f in *456*; do echo mv -i -- "$f" "${f//456/555}"; done


        here we re iterating over the files having 456 in their names, and the parameter expansion pattern ${f//456/555} will replace all 456 substrings in the filename with 555.



        The above will do the dry-run by showing what mv command will be run, you can remove echo to let the action take place:



        for f in *456*; do mv -i -- "$f" "${f//456/555}"; done




        With rename (prename):



        rename -n 's/456/555/g' *456*


        this will replace all (g) 456 substring from filenames with 555 (s/456/555/).



        -n will do the dry-run, if you are satisfied with the changes to be made, remove -n to let the actual renaming take place:



        rename 's/456/555/g' *456*





        share|improve this answer














        With only shell, using parameter expansion:



        for f in *456*; do echo mv -i -- "$f" "${f//456/555}"; done


        here we re iterating over the files having 456 in their names, and the parameter expansion pattern ${f//456/555} will replace all 456 substrings in the filename with 555.



        The above will do the dry-run by showing what mv command will be run, you can remove echo to let the action take place:



        for f in *456*; do mv -i -- "$f" "${f//456/555}"; done




        With rename (prename):



        rename -n 's/456/555/g' *456*


        this will replace all (g) 456 substring from filenames with 555 (s/456/555/).



        -n will do the dry-run, if you are satisfied with the changes to be made, remove -n to let the actual renaming take place:



        rename 's/456/555/g' *456*






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Oct 12 '16 at 21:27

























        answered Oct 12 '16 at 21:21









        heemayl

        34.2k371101




        34.2k371101






















            up vote
            0
            down vote













            which -a rename


            Will tell you if any rename tools are on your $PATH.



            rename 's/456/555/g' *


            Is the preferred syntax for doing what you want (As stated in the manual). If you have no or an old version of rename without regex just download (official) prename Which is a perl script debian like systems use.






            share|improve this answer























            • The OP said they no longer had rename, so suggesting they use rename (of any flavour) doesn't seem particularly helpful.
              – roaima
              Oct 12 '16 at 21:26










            • @roaina the OP is using rename wrong resulting in no action. Likely 'which rename' exists. Also if the OP really is missing it I informed him how to get it.
              – user1133275
              Oct 12 '16 at 21:30










            • Mmm ok. Perhaps.
              – roaima
              Oct 12 '16 at 21:35

















            up vote
            0
            down vote













            which -a rename


            Will tell you if any rename tools are on your $PATH.



            rename 's/456/555/g' *


            Is the preferred syntax for doing what you want (As stated in the manual). If you have no or an old version of rename without regex just download (official) prename Which is a perl script debian like systems use.






            share|improve this answer























            • The OP said they no longer had rename, so suggesting they use rename (of any flavour) doesn't seem particularly helpful.
              – roaima
              Oct 12 '16 at 21:26










            • @roaina the OP is using rename wrong resulting in no action. Likely 'which rename' exists. Also if the OP really is missing it I informed him how to get it.
              – user1133275
              Oct 12 '16 at 21:30










            • Mmm ok. Perhaps.
              – roaima
              Oct 12 '16 at 21:35















            up vote
            0
            down vote










            up vote
            0
            down vote









            which -a rename


            Will tell you if any rename tools are on your $PATH.



            rename 's/456/555/g' *


            Is the preferred syntax for doing what you want (As stated in the manual). If you have no or an old version of rename without regex just download (official) prename Which is a perl script debian like systems use.






            share|improve this answer














            which -a rename


            Will tell you if any rename tools are on your $PATH.



            rename 's/456/555/g' *


            Is the preferred syntax for doing what you want (As stated in the manual). If you have no or an old version of rename without regex just download (official) prename Which is a perl script debian like systems use.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Oct 13 '16 at 4:15

























            answered Oct 12 '16 at 21:23









            user1133275

            2,667415




            2,667415












            • The OP said they no longer had rename, so suggesting they use rename (of any flavour) doesn't seem particularly helpful.
              – roaima
              Oct 12 '16 at 21:26










            • @roaina the OP is using rename wrong resulting in no action. Likely 'which rename' exists. Also if the OP really is missing it I informed him how to get it.
              – user1133275
              Oct 12 '16 at 21:30










            • Mmm ok. Perhaps.
              – roaima
              Oct 12 '16 at 21:35




















            • The OP said they no longer had rename, so suggesting they use rename (of any flavour) doesn't seem particularly helpful.
              – roaima
              Oct 12 '16 at 21:26










            • @roaina the OP is using rename wrong resulting in no action. Likely 'which rename' exists. Also if the OP really is missing it I informed him how to get it.
              – user1133275
              Oct 12 '16 at 21:30










            • Mmm ok. Perhaps.
              – roaima
              Oct 12 '16 at 21:35


















            The OP said they no longer had rename, so suggesting they use rename (of any flavour) doesn't seem particularly helpful.
            – roaima
            Oct 12 '16 at 21:26




            The OP said they no longer had rename, so suggesting they use rename (of any flavour) doesn't seem particularly helpful.
            – roaima
            Oct 12 '16 at 21:26












            @roaina the OP is using rename wrong resulting in no action. Likely 'which rename' exists. Also if the OP really is missing it I informed him how to get it.
            – user1133275
            Oct 12 '16 at 21:30




            @roaina the OP is using rename wrong resulting in no action. Likely 'which rename' exists. Also if the OP really is missing it I informed him how to get it.
            – user1133275
            Oct 12 '16 at 21:30












            Mmm ok. Perhaps.
            – roaima
            Oct 12 '16 at 21:35






            Mmm ok. Perhaps.
            – roaima
            Oct 12 '16 at 21:35












            up vote
            0
            down vote













            (Moved from a question intended as an answer here)



            I have found the answer to my question:



            #! /bin/csh -f
            #----------------------------------------------------------------------
            # Script Name: moveme Date: 05/07/96
            # Written by: John W. Woolsey Rev: 10/11/99
            #
            # Description:
            # Renames a set of files that contain a particular search string
            # to file names that contain a replacement string.
            #
            # Syntax: moveme <search_string> <replace_string>
            #
            # Where:
            # <search_string> is the name of the file name search string.
            # <replace_string> is the name of the file name replace string.
            #----------------------------------------------------------------------
            #
            onintr catch
            if ($#argv != 2) goto syntax

            ls -d *$1* | sed "s/(.*)$1(.*)/mv & 1$22/" | sh
            exit 0

            syntax:
            echo "Syntax: `basename $0` <search_string> <replace_string>"
            exit 1

            catch:
            echo "`basename $0` was interrupted or terminated abnormally."
            exit 1





            share|improve this answer























            • Huh, a csh script that generate sh code...
              – Kusalananda
              Jul 28 at 17:28















            up vote
            0
            down vote













            (Moved from a question intended as an answer here)



            I have found the answer to my question:



            #! /bin/csh -f
            #----------------------------------------------------------------------
            # Script Name: moveme Date: 05/07/96
            # Written by: John W. Woolsey Rev: 10/11/99
            #
            # Description:
            # Renames a set of files that contain a particular search string
            # to file names that contain a replacement string.
            #
            # Syntax: moveme <search_string> <replace_string>
            #
            # Where:
            # <search_string> is the name of the file name search string.
            # <replace_string> is the name of the file name replace string.
            #----------------------------------------------------------------------
            #
            onintr catch
            if ($#argv != 2) goto syntax

            ls -d *$1* | sed "s/(.*)$1(.*)/mv & 1$22/" | sh
            exit 0

            syntax:
            echo "Syntax: `basename $0` <search_string> <replace_string>"
            exit 1

            catch:
            echo "`basename $0` was interrupted or terminated abnormally."
            exit 1





            share|improve this answer























            • Huh, a csh script that generate sh code...
              – Kusalananda
              Jul 28 at 17:28













            up vote
            0
            down vote










            up vote
            0
            down vote









            (Moved from a question intended as an answer here)



            I have found the answer to my question:



            #! /bin/csh -f
            #----------------------------------------------------------------------
            # Script Name: moveme Date: 05/07/96
            # Written by: John W. Woolsey Rev: 10/11/99
            #
            # Description:
            # Renames a set of files that contain a particular search string
            # to file names that contain a replacement string.
            #
            # Syntax: moveme <search_string> <replace_string>
            #
            # Where:
            # <search_string> is the name of the file name search string.
            # <replace_string> is the name of the file name replace string.
            #----------------------------------------------------------------------
            #
            onintr catch
            if ($#argv != 2) goto syntax

            ls -d *$1* | sed "s/(.*)$1(.*)/mv & 1$22/" | sh
            exit 0

            syntax:
            echo "Syntax: `basename $0` <search_string> <replace_string>"
            exit 1

            catch:
            echo "`basename $0` was interrupted or terminated abnormally."
            exit 1





            share|improve this answer














            (Moved from a question intended as an answer here)



            I have found the answer to my question:



            #! /bin/csh -f
            #----------------------------------------------------------------------
            # Script Name: moveme Date: 05/07/96
            # Written by: John W. Woolsey Rev: 10/11/99
            #
            # Description:
            # Renames a set of files that contain a particular search string
            # to file names that contain a replacement string.
            #
            # Syntax: moveme <search_string> <replace_string>
            #
            # Where:
            # <search_string> is the name of the file name search string.
            # <replace_string> is the name of the file name replace string.
            #----------------------------------------------------------------------
            #
            onintr catch
            if ($#argv != 2) goto syntax

            ls -d *$1* | sed "s/(.*)$1(.*)/mv & 1$22/" | sh
            exit 0

            syntax:
            echo "Syntax: `basename $0` <search_string> <replace_string>"
            exit 1

            catch:
            echo "`basename $0` was interrupted or terminated abnormally."
            exit 1






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Apr 13 '17 at 12:36


























            community wiki





            2 revs
            Michael Mrozek













            • Huh, a csh script that generate sh code...
              – Kusalananda
              Jul 28 at 17:28


















            • Huh, a csh script that generate sh code...
              – Kusalananda
              Jul 28 at 17:28
















            Huh, a csh script that generate sh code...
            – Kusalananda
            Jul 28 at 17:28




            Huh, a csh script that generate sh code...
            – Kusalananda
            Jul 28 at 17:28


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f316038%2fchange-part-of-the-filename-on-multiple-files-in-a-directory%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            List directoties down one level, excluding some named directories and files

            list processes belonging to a network namespace

            list systemd RuntimeDirectory mounts