Remove empty lines from a fileHow to move multiple IPs to different lines

How to communicate to my GM that not being allowed to use stealth isn't fun for me?

Why was this person allowed to become Grand Maester?

Extreme flexible working hours: how to get to know people and activities?

Russian word for a male zebra

Who enforces MPAA rating adherence?

60s or 70s novel about Empire of Man making 1st contact with 1st discovered alien race

Are there any important biographies of nobodies?

How to hide rifle during medieval town entrance inspection?

Who won a Game of Bar Dice?

Why can my keyboard only digest 6 keypresses at a time?

Why are trash cans referred to as "zafacón" in Puerto Rico?

Is it possible to have 2 different but equal size real number sets that have the same mean and standard deviation?

Does the 2019 UA Artificer's Many-Handed Pouch infusion enable unlimited infinite-range cross-planar communication?

Live action TV show where High school Kids go into the virtual world and have to clear levels

Align equations within one column

Is an entry level DSLR going to shoot nice portrait pictures?

Determining fair price for profitable mobile app business

Fixing obscure 8080 emulator bug?

Why does logistic function use e rather than 2?

New pedal fell off maybe 50 miles after installation. Should I replace the entire crank, just the arm, or repair the thread?

LuaLaTex - how to use number, computed later in the document

You have (3^2 + 2^3 + 2^2) Guesses Left. Figure out the Last one

sed + add word before string only if not exists

Why does the Mishnah use the terms poor person and homeowner when discussing carrying on Shabbat?



Remove empty lines from a file


How to move multiple IPs to different lines













2















I'm able to find empty lines with /^$, but when I go to remove them using :%s/^$//, nothing seems to happen. Yet, some form of substitution is being made, because the status line reads XX substitutions on XX lines where XX is the number of empty lines in the file.



Questions:



  1. What substitutions are being made, as indicated by the status line?

  2. How do I accomplish what I want to do (eliminate empty lines from a file)?









share|improve this question






















  • One answer to #2 is :g/^$/d

    – chb
    Jun 1 at 1:46











  • A solution would be to replace an actual character: :%s/^n// but that depends on file format.

    – aragaer
    Jun 1 at 10:26















2















I'm able to find empty lines with /^$, but when I go to remove them using :%s/^$//, nothing seems to happen. Yet, some form of substitution is being made, because the status line reads XX substitutions on XX lines where XX is the number of empty lines in the file.



Questions:



  1. What substitutions are being made, as indicated by the status line?

  2. How do I accomplish what I want to do (eliminate empty lines from a file)?









share|improve this question






















  • One answer to #2 is :g/^$/d

    – chb
    Jun 1 at 1:46











  • A solution would be to replace an actual character: :%s/^n// but that depends on file format.

    – aragaer
    Jun 1 at 10:26













2












2








2








I'm able to find empty lines with /^$, but when I go to remove them using :%s/^$//, nothing seems to happen. Yet, some form of substitution is being made, because the status line reads XX substitutions on XX lines where XX is the number of empty lines in the file.



Questions:



  1. What substitutions are being made, as indicated by the status line?

  2. How do I accomplish what I want to do (eliminate empty lines from a file)?









share|improve this question














I'm able to find empty lines with /^$, but when I go to remove them using :%s/^$//, nothing seems to happen. Yet, some form of substitution is being made, because the status line reads XX substitutions on XX lines where XX is the number of empty lines in the file.



Questions:



  1. What substitutions are being made, as indicated by the status line?

  2. How do I accomplish what I want to do (eliminate empty lines from a file)?






substitute






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jun 1 at 1:24









chbchb

1154




1154












  • One answer to #2 is :g/^$/d

    – chb
    Jun 1 at 1:46











  • A solution would be to replace an actual character: :%s/^n// but that depends on file format.

    – aragaer
    Jun 1 at 10:26

















  • One answer to #2 is :g/^$/d

    – chb
    Jun 1 at 1:46











  • A solution would be to replace an actual character: :%s/^n// but that depends on file format.

    – aragaer
    Jun 1 at 10:26
















One answer to #2 is :g/^$/d

– chb
Jun 1 at 1:46





One answer to #2 is :g/^$/d

– chb
Jun 1 at 1:46













A solution would be to replace an actual character: :%s/^n// but that depends on file format.

– aragaer
Jun 1 at 10:26





A solution would be to replace an actual character: :%s/^n// but that depends on file format.

– aragaer
Jun 1 at 10:26










1 Answer
1






active

oldest

votes


















8















  1. ^ and $ are zero-width items, so when you do :%s/^$// you’re substituting zero characters for zero characters

  2. To actually perform the substitution, the idioms are


:g/^$/d


and



:g/^$/j





share|improve this answer

























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "599"
    ;
    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
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f20182%2fremove-empty-lines-from-a-file%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    8















    1. ^ and $ are zero-width items, so when you do :%s/^$// you’re substituting zero characters for zero characters

    2. To actually perform the substitution, the idioms are


    :g/^$/d


    and



    :g/^$/j





    share|improve this answer





























      8















      1. ^ and $ are zero-width items, so when you do :%s/^$// you’re substituting zero characters for zero characters

      2. To actually perform the substitution, the idioms are


      :g/^$/d


      and



      :g/^$/j





      share|improve this answer



























        8












        8








        8








        1. ^ and $ are zero-width items, so when you do :%s/^$// you’re substituting zero characters for zero characters

        2. To actually perform the substitution, the idioms are


        :g/^$/d


        and



        :g/^$/j





        share|improve this answer
















        1. ^ and $ are zero-width items, so when you do :%s/^$// you’re substituting zero characters for zero characters

        2. To actually perform the substitution, the idioms are


        :g/^$/d


        and



        :g/^$/j






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jun 2 at 12:46

























        answered Jun 1 at 3:23









        D. Ben KnobleD. Ben Knoble

        3,0431521




        3,0431521



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Vi and Vim 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%2fvi.stackexchange.com%2fquestions%2f20182%2fremove-empty-lines-from-a-file%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

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

            Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?