I want to rename all files in a directory from *.ts to *.mkv












1















Rename all the files in .ts files in a directory
My echo command works but not if I try to make it a new variable.



#!/bin/sh
for file in "${1}"/*.ts; do
echo ${file} | sed -e 's|.ts|.mkv|'
new_name=${file} | sed -e 's|.ts|.mkv|'
done









share|improve this question









New contributor




NasKar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Just use rename. If the Perl version, it's just rename 's/.ts$/.mkv' *.

    – Sparhawk
    4 hours ago






  • 5





    Possible duplicate of Changing extension to multiple files

    – Jeff Schaller
    4 hours ago











  • I want to save the renamed file to a variable to pass in another command in the script (input name -> output name). The examples are for renaming them in the directory

    – NasKar
    2 hours ago






  • 1





    Please edit your question to include this information.

    – Sparhawk
    2 hours ago











  • Are your files named with .ts actually Matroska files?

    – jamesdlin
    just now
















1















Rename all the files in .ts files in a directory
My echo command works but not if I try to make it a new variable.



#!/bin/sh
for file in "${1}"/*.ts; do
echo ${file} | sed -e 's|.ts|.mkv|'
new_name=${file} | sed -e 's|.ts|.mkv|'
done









share|improve this question









New contributor




NasKar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Just use rename. If the Perl version, it's just rename 's/.ts$/.mkv' *.

    – Sparhawk
    4 hours ago






  • 5





    Possible duplicate of Changing extension to multiple files

    – Jeff Schaller
    4 hours ago











  • I want to save the renamed file to a variable to pass in another command in the script (input name -> output name). The examples are for renaming them in the directory

    – NasKar
    2 hours ago






  • 1





    Please edit your question to include this information.

    – Sparhawk
    2 hours ago











  • Are your files named with .ts actually Matroska files?

    – jamesdlin
    just now














1












1








1








Rename all the files in .ts files in a directory
My echo command works but not if I try to make it a new variable.



#!/bin/sh
for file in "${1}"/*.ts; do
echo ${file} | sed -e 's|.ts|.mkv|'
new_name=${file} | sed -e 's|.ts|.mkv|'
done









share|improve this question









New contributor




NasKar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












Rename all the files in .ts files in a directory
My echo command works but not if I try to make it a new variable.



#!/bin/sh
for file in "${1}"/*.ts; do
echo ${file} | sed -e 's|.ts|.mkv|'
new_name=${file} | sed -e 's|.ts|.mkv|'
done






shell-script files rename






share|improve this question









New contributor




NasKar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




NasKar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 4 hours ago









Jeff Schaller

40.1k1054126




40.1k1054126






New contributor




NasKar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 4 hours ago









NasKarNasKar

61




61




New contributor




NasKar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





NasKar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






NasKar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • Just use rename. If the Perl version, it's just rename 's/.ts$/.mkv' *.

    – Sparhawk
    4 hours ago






  • 5





    Possible duplicate of Changing extension to multiple files

    – Jeff Schaller
    4 hours ago











  • I want to save the renamed file to a variable to pass in another command in the script (input name -> output name). The examples are for renaming them in the directory

    – NasKar
    2 hours ago






  • 1





    Please edit your question to include this information.

    – Sparhawk
    2 hours ago











  • Are your files named with .ts actually Matroska files?

    – jamesdlin
    just now



















  • Just use rename. If the Perl version, it's just rename 's/.ts$/.mkv' *.

    – Sparhawk
    4 hours ago






  • 5





    Possible duplicate of Changing extension to multiple files

    – Jeff Schaller
    4 hours ago











  • I want to save the renamed file to a variable to pass in another command in the script (input name -> output name). The examples are for renaming them in the directory

    – NasKar
    2 hours ago






  • 1





    Please edit your question to include this information.

    – Sparhawk
    2 hours ago











  • Are your files named with .ts actually Matroska files?

    – jamesdlin
    just now

















Just use rename. If the Perl version, it's just rename 's/.ts$/.mkv' *.

– Sparhawk
4 hours ago





Just use rename. If the Perl version, it's just rename 's/.ts$/.mkv' *.

– Sparhawk
4 hours ago




5




5





Possible duplicate of Changing extension to multiple files

– Jeff Schaller
4 hours ago





Possible duplicate of Changing extension to multiple files

– Jeff Schaller
4 hours ago













I want to save the renamed file to a variable to pass in another command in the script (input name -> output name). The examples are for renaming them in the directory

– NasKar
2 hours ago





I want to save the renamed file to a variable to pass in another command in the script (input name -> output name). The examples are for renaming them in the directory

– NasKar
2 hours ago




1




1





Please edit your question to include this information.

– Sparhawk
2 hours ago





Please edit your question to include this information.

– Sparhawk
2 hours ago













Are your files named with .ts actually Matroska files?

– jamesdlin
just now





Are your files named with .ts actually Matroska files?

– jamesdlin
just now










3 Answers
3






active

oldest

votes


















1














The simplest solution would be to tell you to change the assignment to:



new_name=$( echo ${file} | sed -e 's|.ts|.mkv|' )


But a better solution would be to do:



new_name="${file%.ts}.mkv"





share|improve this answer































    1














    #!/bin/sh
    for file in "${1}"/*.ts; do
    mv "${file}" "$(basename "${file}").mkv"
    done





    share|improve this answer































      0














      find . -maxdepth 1 -type f -name '*.ts' -exec rename .ts .mkv {} "+"


      Run this in the directory containing the .ts files.






      share|improve this answer























        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',
        autoActivateHeartbeat: false,
        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
        });


        }
        });






        NasKar is a new contributor. Be nice, and check out our Code of Conduct.










        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f497101%2fi-want-to-rename-all-files-in-a-directory-from-ts-to-mkv%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        1














        The simplest solution would be to tell you to change the assignment to:



        new_name=$( echo ${file} | sed -e 's|.ts|.mkv|' )


        But a better solution would be to do:



        new_name="${file%.ts}.mkv"





        share|improve this answer




























          1














          The simplest solution would be to tell you to change the assignment to:



          new_name=$( echo ${file} | sed -e 's|.ts|.mkv|' )


          But a better solution would be to do:



          new_name="${file%.ts}.mkv"





          share|improve this answer


























            1












            1








            1







            The simplest solution would be to tell you to change the assignment to:



            new_name=$( echo ${file} | sed -e 's|.ts|.mkv|' )


            But a better solution would be to do:



            new_name="${file%.ts}.mkv"





            share|improve this answer













            The simplest solution would be to tell you to change the assignment to:



            new_name=$( echo ${file} | sed -e 's|.ts|.mkv|' )


            But a better solution would be to do:



            new_name="${file%.ts}.mkv"






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 hours ago









            IsaacIsaac

            11.7k11752




            11.7k11752

























                1














                #!/bin/sh
                for file in "${1}"/*.ts; do
                mv "${file}" "$(basename "${file}").mkv"
                done





                share|improve this answer




























                  1














                  #!/bin/sh
                  for file in "${1}"/*.ts; do
                  mv "${file}" "$(basename "${file}").mkv"
                  done





                  share|improve this answer


























                    1












                    1








                    1







                    #!/bin/sh
                    for file in "${1}"/*.ts; do
                    mv "${file}" "$(basename "${file}").mkv"
                    done





                    share|improve this answer













                    #!/bin/sh
                    for file in "${1}"/*.ts; do
                    mv "${file}" "$(basename "${file}").mkv"
                    done






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 2 hours ago









                    nyetnyet

                    13113




                    13113























                        0














                        find . -maxdepth 1 -type f -name '*.ts' -exec rename .ts .mkv {} "+"


                        Run this in the directory containing the .ts files.






                        share|improve this answer




























                          0














                          find . -maxdepth 1 -type f -name '*.ts' -exec rename .ts .mkv {} "+"


                          Run this in the directory containing the .ts files.






                          share|improve this answer


























                            0












                            0








                            0







                            find . -maxdepth 1 -type f -name '*.ts' -exec rename .ts .mkv {} "+"


                            Run this in the directory containing the .ts files.






                            share|improve this answer













                            find . -maxdepth 1 -type f -name '*.ts' -exec rename .ts .mkv {} "+"


                            Run this in the directory containing the .ts files.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 43 mins ago









                            Niko GambtNiko Gambt

                            1406




                            1406






















                                NasKar is a new contributor. Be nice, and check out our Code of Conduct.










                                draft saved

                                draft discarded


















                                NasKar is a new contributor. Be nice, and check out our Code of Conduct.













                                NasKar is a new contributor. Be nice, and check out our Code of Conduct.












                                NasKar is a new contributor. Be nice, and check out our Code of Conduct.
















                                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.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f497101%2fi-want-to-rename-all-files-in-a-directory-from-ts-to-mkv%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

                                Ponta tanko

                                Tantalo (mitologio)

                                Erzsébet Schaár