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
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:
- What substitutions are being made, as indicated by the status line?
- How do I accomplish what I want to do (eliminate empty lines from a file)?
substitute
add a comment |
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:
- What substitutions are being made, as indicated by the status line?
- How do I accomplish what I want to do (eliminate empty lines from a file)?
substitute
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
add a comment |
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:
- What substitutions are being made, as indicated by the status line?
- How do I accomplish what I want to do (eliminate empty lines from a file)?
substitute
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:
- What substitutions are being made, as indicated by the status line?
- How do I accomplish what I want to do (eliminate empty lines from a file)?
substitute
substitute
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
^
and$
are zero-width items, so when you do:%s/^$//
you’re substituting zero characters for zero characters- To actually perform the substitution, the idioms are
:g/^$/d
and
:g/^$/j
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
^
and$
are zero-width items, so when you do:%s/^$//
you’re substituting zero characters for zero characters- To actually perform the substitution, the idioms are
:g/^$/d
and
:g/^$/j
add a comment |
^
and$
are zero-width items, so when you do:%s/^$//
you’re substituting zero characters for zero characters- To actually perform the substitution, the idioms are
:g/^$/d
and
:g/^$/j
add a comment |
^
and$
are zero-width items, so when you do:%s/^$//
you’re substituting zero characters for zero characters- To actually perform the substitution, the idioms are
:g/^$/d
and
:g/^$/j
^
and$
are zero-width items, so when you do:%s/^$//
you’re substituting zero characters for zero characters- To actually perform the substitution, the idioms are
:g/^$/d
and
:g/^$/j
edited Jun 2 at 12:46
answered Jun 1 at 3:23
D. Ben KnobleD. Ben Knoble
3,0431521
3,0431521
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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