How do I create a multiline text file with Echo in Windows command prompt?












11















I'm using Windows 7 and I would like to quickly create a small text file with a few lines of text in the Command prompt.



I can create a single line text file with:



echo hello > myfile.txt


but how can I create a text file with multiple lines using this echo command? I have tried with the following, which doesn't work when I read the file with more:



echo hellonsecond line > myfile.txt


Any suggestions? Or is there any other standard command that I can use for this instead of echo?










share|improve this question























  • stackoverflow.com/questions/132799/…

    – akira
    Nov 3 '12 at 11:10
















11















I'm using Windows 7 and I would like to quickly create a small text file with a few lines of text in the Command prompt.



I can create a single line text file with:



echo hello > myfile.txt


but how can I create a text file with multiple lines using this echo command? I have tried with the following, which doesn't work when I read the file with more:



echo hellonsecond line > myfile.txt


Any suggestions? Or is there any other standard command that I can use for this instead of echo?










share|improve this question























  • stackoverflow.com/questions/132799/…

    – akira
    Nov 3 '12 at 11:10














11












11








11


3






I'm using Windows 7 and I would like to quickly create a small text file with a few lines of text in the Command prompt.



I can create a single line text file with:



echo hello > myfile.txt


but how can I create a text file with multiple lines using this echo command? I have tried with the following, which doesn't work when I read the file with more:



echo hellonsecond line > myfile.txt


Any suggestions? Or is there any other standard command that I can use for this instead of echo?










share|improve this question














I'm using Windows 7 and I would like to quickly create a small text file with a few lines of text in the Command prompt.



I can create a single line text file with:



echo hello > myfile.txt


but how can I create a text file with multiple lines using this echo command? I have tried with the following, which doesn't work when I read the file with more:



echo hellonsecond line > myfile.txt


Any suggestions? Or is there any other standard command that I can use for this instead of echo?







windows command-line echo textfiles






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 3 '12 at 11:06









JonasJonas

9,6723994120




9,6723994120













  • stackoverflow.com/questions/132799/…

    – akira
    Nov 3 '12 at 11:10



















  • stackoverflow.com/questions/132799/…

    – akira
    Nov 3 '12 at 11:10

















stackoverflow.com/questions/132799/…

– akira
Nov 3 '12 at 11:10





stackoverflow.com/questions/132799/…

– akira
Nov 3 '12 at 11:10










3 Answers
3






active

oldest

votes


















14














You could use the >> characters to append a second line to the file, e.g.



echo hello > myfile.txt
echo second line >> myfile.txt





share|improve this answer

































    17














    There are three ways.





    1. Append each line using >>:



      C:UsersElias>echo foo > a.txt
      C:UsersElias>echo bar >> a.txt



    2. Use parentheses to echo multiple lines:



      C:UsersElias>(echo foo
      More? echo bar) > a.txt



    3. Type caret (^) and hit ENTER twice after each line to continue adding lines:



      C:UsersElias>echo foo^
      More?
      More? bar > a.txt



    All the above produce the same file:



    C:UsersElias>type a.txt
    foo
    bar





    share|improve this answer

































      0














      You can put a space between each line to write:



      echo line1 line2 "line 3" > file.txt





      share|improve this answer























        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "3"
        };
        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: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        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%2fsuperuser.com%2fquestions%2f498908%2fhow-do-i-create-a-multiline-text-file-with-echo-in-windows-command-prompt%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









        14














        You could use the >> characters to append a second line to the file, e.g.



        echo hello > myfile.txt
        echo second line >> myfile.txt





        share|improve this answer






























          14














          You could use the >> characters to append a second line to the file, e.g.



          echo hello > myfile.txt
          echo second line >> myfile.txt





          share|improve this answer




























            14












            14








            14







            You could use the >> characters to append a second line to the file, e.g.



            echo hello > myfile.txt
            echo second line >> myfile.txt





            share|improve this answer















            You could use the >> characters to append a second line to the file, e.g.



            echo hello > myfile.txt
            echo second line >> myfile.txt






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jun 19 '15 at 0:53









            Bugalugs Nash

            1115




            1115










            answered Nov 3 '12 at 11:09









            Ian BakerIan Baker

            16613




            16613

























                17














                There are three ways.





                1. Append each line using >>:



                  C:UsersElias>echo foo > a.txt
                  C:UsersElias>echo bar >> a.txt



                2. Use parentheses to echo multiple lines:



                  C:UsersElias>(echo foo
                  More? echo bar) > a.txt



                3. Type caret (^) and hit ENTER twice after each line to continue adding lines:



                  C:UsersElias>echo foo^
                  More?
                  More? bar > a.txt



                All the above produce the same file:



                C:UsersElias>type a.txt
                foo
                bar





                share|improve this answer






























                  17














                  There are three ways.





                  1. Append each line using >>:



                    C:UsersElias>echo foo > a.txt
                    C:UsersElias>echo bar >> a.txt



                  2. Use parentheses to echo multiple lines:



                    C:UsersElias>(echo foo
                    More? echo bar) > a.txt



                  3. Type caret (^) and hit ENTER twice after each line to continue adding lines:



                    C:UsersElias>echo foo^
                    More?
                    More? bar > a.txt



                  All the above produce the same file:



                  C:UsersElias>type a.txt
                  foo
                  bar





                  share|improve this answer




























                    17












                    17








                    17







                    There are three ways.





                    1. Append each line using >>:



                      C:UsersElias>echo foo > a.txt
                      C:UsersElias>echo bar >> a.txt



                    2. Use parentheses to echo multiple lines:



                      C:UsersElias>(echo foo
                      More? echo bar) > a.txt



                    3. Type caret (^) and hit ENTER twice after each line to continue adding lines:



                      C:UsersElias>echo foo^
                      More?
                      More? bar > a.txt



                    All the above produce the same file:



                    C:UsersElias>type a.txt
                    foo
                    bar





                    share|improve this answer















                    There are three ways.





                    1. Append each line using >>:



                      C:UsersElias>echo foo > a.txt
                      C:UsersElias>echo bar >> a.txt



                    2. Use parentheses to echo multiple lines:



                      C:UsersElias>(echo foo
                      More? echo bar) > a.txt



                    3. Type caret (^) and hit ENTER twice after each line to continue adding lines:



                      C:UsersElias>echo foo^
                      More?
                      More? bar > a.txt



                    All the above produce the same file:



                    C:UsersElias>type a.txt
                    foo
                    bar






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Jun 19 '15 at 1:31









                    Bugalugs Nash

                    1115




                    1115










                    answered Nov 3 '12 at 11:26









                    efotinisefotinis

                    3,1741622




                    3,1741622























                        0














                        You can put a space between each line to write:



                        echo line1 line2 "line 3" > file.txt





                        share|improve this answer




























                          0














                          You can put a space between each line to write:



                          echo line1 line2 "line 3" > file.txt





                          share|improve this answer


























                            0












                            0








                            0







                            You can put a space between each line to write:



                            echo line1 line2 "line 3" > file.txt





                            share|improve this answer













                            You can put a space between each line to write:



                            echo line1 line2 "line 3" > file.txt






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 21 at 14:02









                            CarlCarl

                            1




                            1






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Super User!


                                • 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%2fsuperuser.com%2fquestions%2f498908%2fhow-do-i-create-a-multiline-text-file-with-echo-in-windows-command-prompt%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

                                How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

                                is 'sed' thread safe

                                How to make a Squid Proxy server?