How to count empty line using grepWhat makes grep consider a file to be binary?Count lines matching pattern...
When did computers stop checking memory on boot?
UK citizen travelling to France at the end of November
How should Thaumaturgy's "three times as loud as normal" be interpreted?
What is the difference between a translation and a Galilean transformation?
Are programming languages necessary/useful for operations research practitioner?
How should we understand "unobscured by flying friends" in this context?
How to set any file manager in Linux to show the duration like the Length feature in Windows Explorer?
Is it unavoidable taking shortcuts in software development sometimes?
What is the difference between tl_to_str:V and tl_to_str:N?
A word for decorative cords on uniforms
Chandrayaan 2: Why is Vikram Lander's life limited to 14 Days?
Bit floating sequence
Owner keeps cutting corners and poaching workers for his other company
I multiply the source, you (probably) multiply the output!
How can Schrödinger's cat be both dead and alive?
Features seen on the Space Shuttle's solid booster; what does "LOADED" mean exactly?
Is a MySQL database a viable alternative to LDAP?
Why does low tire pressure decrease fuel economy?
How can faith be maintained in a world of living gods?
pgfgantt: month displayed as single letter
How do you say "to hell with everything" in French?
Are personality traits, ideals, bonds, and flaws required?
WPF MVVM ColorLister with navigation
I need to know information from an old German birth certificate
How to count empty line using grep
What makes grep consider a file to be binary?Count lines matching pattern and matching previous lineCount number of a substring repetition in a stringHow to “grep” for line length *not* in a given range?Count text occurrences per lineHow do I grep many files for many strings?Using grep to find multiple repeating characters in a wordsearching letters in one line using grep and wc
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I have a text file. Some lines contain text while others do not (just empty line without any spaces or characters:
123
// comment
45
As you can see, there is a line above //comment
. If I want to count the times such line exist in my file, how can I grep them?
text-processing files grep search
New contributor
add a comment |
I have a text file. Some lines contain text while others do not (just empty line without any spaces or characters:
123
// comment
45
As you can see, there is a line above //comment
. If I want to count the times such line exist in my file, how can I grep them?
text-processing files grep search
New contributor
add a comment |
I have a text file. Some lines contain text while others do not (just empty line without any spaces or characters:
123
// comment
45
As you can see, there is a line above //comment
. If I want to count the times such line exist in my file, how can I grep them?
text-processing files grep search
New contributor
I have a text file. Some lines contain text while others do not (just empty line without any spaces or characters:
123
// comment
45
As you can see, there is a line above //comment
. If I want to count the times such line exist in my file, how can I grep them?
text-processing files grep search
text-processing files grep search
New contributor
New contributor
New contributor
asked 36 mins ago
user12019159user12019159
31 bronze badge
31 bronze badge
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can grep empty lines with grep '^$' file
and count the lines with wc -l
. Combined it's:
grep '^$' file | wc -l
or even shorter with grep
's count option -c
or --count
grep -c '^$' file
1
See alsogrep -c
– Stephen Harris
29 mins ago
Thanks @StephenHarris ! I totally forgot this option.
– Freddy
25 mins ago
add a comment |
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/4.0/"u003ecc by-sa 4.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
});
}
});
user12019159 is a new contributor. Be nice, and check out our Code of Conduct.
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%2funix.stackexchange.com%2fquestions%2f539706%2fhow-to-count-empty-line-using-grep%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
You can grep empty lines with grep '^$' file
and count the lines with wc -l
. Combined it's:
grep '^$' file | wc -l
or even shorter with grep
's count option -c
or --count
grep -c '^$' file
1
See alsogrep -c
– Stephen Harris
29 mins ago
Thanks @StephenHarris ! I totally forgot this option.
– Freddy
25 mins ago
add a comment |
You can grep empty lines with grep '^$' file
and count the lines with wc -l
. Combined it's:
grep '^$' file | wc -l
or even shorter with grep
's count option -c
or --count
grep -c '^$' file
1
See alsogrep -c
– Stephen Harris
29 mins ago
Thanks @StephenHarris ! I totally forgot this option.
– Freddy
25 mins ago
add a comment |
You can grep empty lines with grep '^$' file
and count the lines with wc -l
. Combined it's:
grep '^$' file | wc -l
or even shorter with grep
's count option -c
or --count
grep -c '^$' file
You can grep empty lines with grep '^$' file
and count the lines with wc -l
. Combined it's:
grep '^$' file | wc -l
or even shorter with grep
's count option -c
or --count
grep -c '^$' file
edited 26 mins ago
answered 31 mins ago
FreddyFreddy
7,4931 gold badge6 silver badges25 bronze badges
7,4931 gold badge6 silver badges25 bronze badges
1
See alsogrep -c
– Stephen Harris
29 mins ago
Thanks @StephenHarris ! I totally forgot this option.
– Freddy
25 mins ago
add a comment |
1
See alsogrep -c
– Stephen Harris
29 mins ago
Thanks @StephenHarris ! I totally forgot this option.
– Freddy
25 mins ago
1
1
See also
grep -c
– Stephen Harris
29 mins ago
See also
grep -c
– Stephen Harris
29 mins ago
Thanks @StephenHarris ! I totally forgot this option.
– Freddy
25 mins ago
Thanks @StephenHarris ! I totally forgot this option.
– Freddy
25 mins ago
add a comment |
user12019159 is a new contributor. Be nice, and check out our Code of Conduct.
user12019159 is a new contributor. Be nice, and check out our Code of Conduct.
user12019159 is a new contributor. Be nice, and check out our Code of Conduct.
user12019159 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.
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%2funix.stackexchange.com%2fquestions%2f539706%2fhow-to-count-empty-line-using-grep%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