How to count number frequency from specific column?Getting data from matching listHow to print top five...
How to check the quality of an audio sample?
Rearranging the formula
TikZ Can I draw an arrow by specifying the initial point, direction, and length?
Are there any double stars that I can actually see orbit each other?
Won 50K! Now what should I do with it
Fix /dev/sdb after using dd with no device inserted
Ambiguous sentences: How to tell when they need fixing?
Construct a pentagon avoiding compass use
Why does the autopilot disengage even when it does not receive pilot input?
Is a public company able to check out who owns its shares in very detailed format?
Is `curl {something} | sudo bash -` a reasonably safe installation method?
QGIS Linestring rendering curves between vertex
Missing Contours in ContourPlot
How can an advanced civilization forget how to manufacture its technology?
How do I write a romance that doesn't look obvious
Should you avoid redundant information after dialogue?
Help with understanding nuances of extremely popular Kyoto-ben (?) tweet
Would letting a multiclass character rebuild their character to be single-classed be game-breaking?
Interpreting the word "randomly"
Why limit to revolvers?
Measuring mystery distances
Why would guns not work in the dungeon?
Why did my rum cake turn black?
Is this floating-point optimization allowed?
How to count number frequency from specific column?
Getting data from matching listHow to print top five highest numbers from a column?How to print incremental count of occurrences of unique values in column 1Count the number of 0 and 1 in a fileCount frequency of specific numbers in a text file of scientific notationsCount number of a substring repetition in a stringAWK - how to get contents of a file pointed by first column of a fileHow to print first column of next line in current line?How to apply awk command on all fields except a few specific rowsCount the number of occurrences of a column value in a TSV file with AWK
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
Below I have given my file (filename = 1.txt) structure. I want to count the number frequency from the first column and it should be started from line 3. Because the first line contains 411 and second line contain some text which is not the interest of mine.
I can count a specific number using below:
awk '($1==15){ ++count } END{ print count }' 1.txt> output.txt
my file structure:
411
Lattice="156.0 0.0 0.0 0.0 156.0 0.0 0.0 0.0 156.0"
1 410.0 2 1
2 1059.0 2 2
2 1060.0 2 3
3 2117.0 2 4
4 4726.0 2 5
5 3219.0 2 6
6 4744.0 2 7
7 4918.0 2 8
8 10686.0 2 9
9 11055.0 2 10
10 16475.0 2 11
11 14698.0 2 12
11 17430.0 2 13
12 15235.0 2 14
13 15799.0 2 15
14 21476.0 2 16
15 18561.0 2 17
15 18562.0 2 18
15 21595.0 2 19
15 21636.0 2 20
15 21684.0 2 21
16 24262.0 2 22
14 21475.0 2 23
17 24674.0 2 24
my desired output
1 1
2 2
3 1
4 1
.
.
14 2
15 5
bash awk grep
New contributor
Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Below I have given my file (filename = 1.txt) structure. I want to count the number frequency from the first column and it should be started from line 3. Because the first line contains 411 and second line contain some text which is not the interest of mine.
I can count a specific number using below:
awk '($1==15){ ++count } END{ print count }' 1.txt> output.txt
my file structure:
411
Lattice="156.0 0.0 0.0 0.0 156.0 0.0 0.0 0.0 156.0"
1 410.0 2 1
2 1059.0 2 2
2 1060.0 2 3
3 2117.0 2 4
4 4726.0 2 5
5 3219.0 2 6
6 4744.0 2 7
7 4918.0 2 8
8 10686.0 2 9
9 11055.0 2 10
10 16475.0 2 11
11 14698.0 2 12
11 17430.0 2 13
12 15235.0 2 14
13 15799.0 2 15
14 21476.0 2 16
15 18561.0 2 17
15 18562.0 2 18
15 21595.0 2 19
15 21636.0 2 20
15 21684.0 2 21
16 24262.0 2 22
14 21475.0 2 23
17 24674.0 2 24
my desired output
1 1
2 2
3 1
4 1
.
.
14 2
15 5
bash awk grep
New contributor
Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Below I have given my file (filename = 1.txt) structure. I want to count the number frequency from the first column and it should be started from line 3. Because the first line contains 411 and second line contain some text which is not the interest of mine.
I can count a specific number using below:
awk '($1==15){ ++count } END{ print count }' 1.txt> output.txt
my file structure:
411
Lattice="156.0 0.0 0.0 0.0 156.0 0.0 0.0 0.0 156.0"
1 410.0 2 1
2 1059.0 2 2
2 1060.0 2 3
3 2117.0 2 4
4 4726.0 2 5
5 3219.0 2 6
6 4744.0 2 7
7 4918.0 2 8
8 10686.0 2 9
9 11055.0 2 10
10 16475.0 2 11
11 14698.0 2 12
11 17430.0 2 13
12 15235.0 2 14
13 15799.0 2 15
14 21476.0 2 16
15 18561.0 2 17
15 18562.0 2 18
15 21595.0 2 19
15 21636.0 2 20
15 21684.0 2 21
16 24262.0 2 22
14 21475.0 2 23
17 24674.0 2 24
my desired output
1 1
2 2
3 1
4 1
.
.
14 2
15 5
bash awk grep
New contributor
Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Below I have given my file (filename = 1.txt) structure. I want to count the number frequency from the first column and it should be started from line 3. Because the first line contains 411 and second line contain some text which is not the interest of mine.
I can count a specific number using below:
awk '($1==15){ ++count } END{ print count }' 1.txt> output.txt
my file structure:
411
Lattice="156.0 0.0 0.0 0.0 156.0 0.0 0.0 0.0 156.0"
1 410.0 2 1
2 1059.0 2 2
2 1060.0 2 3
3 2117.0 2 4
4 4726.0 2 5
5 3219.0 2 6
6 4744.0 2 7
7 4918.0 2 8
8 10686.0 2 9
9 11055.0 2 10
10 16475.0 2 11
11 14698.0 2 12
11 17430.0 2 13
12 15235.0 2 14
13 15799.0 2 15
14 21476.0 2 16
15 18561.0 2 17
15 18562.0 2 18
15 21595.0 2 19
15 21636.0 2 20
15 21684.0 2 21
16 24262.0 2 22
14 21475.0 2 23
17 24674.0 2 24
my desired output
1 1
2 2
3 1
4 1
.
.
14 2
15 5
bash awk grep
bash awk grep
New contributor
Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 6 mins ago
AlexAlex
1
1
New contributor
Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can use an associative array that is keyed on the column value, assigning values only from the third record (line) onward (NR>2):
$ awk 'NR>2 {a[$1]++} END {for (i in a) print i, a[i]}' 1.txt
1 1
2 2
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
11 2
12 1
13 1
14 2
15 5
16 1
17 1
Note that the order of array traversal is not guaranteed - you may need additional sorting if output order is important.
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/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
});
}
});
Alex 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%2f530039%2fhow-to-count-number-frequency-from-specific-column%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 use an associative array that is keyed on the column value, assigning values only from the third record (line) onward (NR>2):
$ awk 'NR>2 {a[$1]++} END {for (i in a) print i, a[i]}' 1.txt
1 1
2 2
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
11 2
12 1
13 1
14 2
15 5
16 1
17 1
Note that the order of array traversal is not guaranteed - you may need additional sorting if output order is important.
add a comment |
You can use an associative array that is keyed on the column value, assigning values only from the third record (line) onward (NR>2):
$ awk 'NR>2 {a[$1]++} END {for (i in a) print i, a[i]}' 1.txt
1 1
2 2
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
11 2
12 1
13 1
14 2
15 5
16 1
17 1
Note that the order of array traversal is not guaranteed - you may need additional sorting if output order is important.
add a comment |
You can use an associative array that is keyed on the column value, assigning values only from the third record (line) onward (NR>2):
$ awk 'NR>2 {a[$1]++} END {for (i in a) print i, a[i]}' 1.txt
1 1
2 2
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
11 2
12 1
13 1
14 2
15 5
16 1
17 1
Note that the order of array traversal is not guaranteed - you may need additional sorting if output order is important.
You can use an associative array that is keyed on the column value, assigning values only from the third record (line) onward (NR>2):
$ awk 'NR>2 {a[$1]++} END {for (i in a) print i, a[i]}' 1.txt
1 1
2 2
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
11 2
12 1
13 1
14 2
15 5
16 1
17 1
Note that the order of array traversal is not guaranteed - you may need additional sorting if output order is important.
answered 4 secs ago
steeldriversteeldriver
40.8k4 gold badges56 silver badges93 bronze badges
40.8k4 gold badges56 silver badges93 bronze badges
add a comment |
add a comment |
Alex is a new contributor. Be nice, and check out our Code of Conduct.
Alex is a new contributor. Be nice, and check out our Code of Conduct.
Alex is a new contributor. Be nice, and check out our Code of Conduct.
Alex 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%2f530039%2fhow-to-count-number-frequency-from-specific-column%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