Sed-Grep-Awk operationsUsing awk to identify the number identical columnsReformatting negative numbers with...
How to make transparent background from pdf to png
Have the UK Conservatives lost the working majority and if so, what does this mean?
Can I do anything else with aspersions other than cast them?
Is there a configuration of the 8-puzzle where locking a tile makes it harder?
Have any astronauts or cosmonauts died in space?
How to store all ctor parameters in fields
Trying to make a 3dplot
Including proofs of known theorems in master's thesis
Can a Way of Shadow Monk use Shadow Step to cling to a dark ceiling?
What could cause an entire planet of humans to become aphasic?
How can I prep for the Curse of Strahd adventure effectively?
What really causes series inductance of capacitors?
Why don't programs completely uninstall (remove all their files) when I remove them?
70s or 80s movie about aliens in a Television
Multiple null checks in Java 8
How can changes in personality/values of a person who turned into a vampire be explained?
What is the reward?
Why is perturbation theory used in quantum mechanics?
3D buried view in Tikz
Can you say "leftside right"?
Boss asked me to sign a resignation paper without a date on it along with my new contract
Buying a "Used" Router
Does しかたない imply disappointment?
Why does this quiz question say that protons and electrons do not combine to form neutrons?
Sed-Grep-Awk operations
Using awk to identify the number identical columnsReformatting negative numbers with sed or awkIs it possible to add consecutive columns in AWKIf column matches another file, print every line with match (awk/grep)How to extract multiple pattern from each line with sed, awk, or grepMultiline Regexp (grep, sed, awk, perl)pattern file as an input to RS,FS in awk/sed/grep to recognize and add columnsawk from different linesmatch two columns from one file to three columns from another file, print out lines from the file with two columnsColumn manipulation using AWK
A file contains 5 columns with numbers
Example:
12 34 67 88 10
4 90 12 10 7
33 12 5 76 34
I would like to print the same number and see how many times it goes out.
Example:
3 : 12
2 : 34
awk sed grep numeric-data
add a comment |
A file contains 5 columns with numbers
Example:
12 34 67 88 10
4 90 12 10 7
33 12 5 76 34
I would like to print the same number and see how many times it goes out.
Example:
3 : 12
2 : 34
awk sed grep numeric-data
presumably only for numbers that occur more than once?
– Jeff Schaller
53 mins ago
Numbers, or digits? How do you arrive at that output?
– Kusalananda
40 mins ago
add a comment |
A file contains 5 columns with numbers
Example:
12 34 67 88 10
4 90 12 10 7
33 12 5 76 34
I would like to print the same number and see how many times it goes out.
Example:
3 : 12
2 : 34
awk sed grep numeric-data
A file contains 5 columns with numbers
Example:
12 34 67 88 10
4 90 12 10 7
33 12 5 76 34
I would like to print the same number and see how many times it goes out.
Example:
3 : 12
2 : 34
awk sed grep numeric-data
awk sed grep numeric-data
edited 53 mins ago
Jeff Schaller
41.8k1156133
41.8k1156133
asked 59 mins ago
InsideMiamiTattooInsideMiamiTattoo
162
162
presumably only for numbers that occur more than once?
– Jeff Schaller
53 mins ago
Numbers, or digits? How do you arrive at that output?
– Kusalananda
40 mins ago
add a comment |
presumably only for numbers that occur more than once?
– Jeff Schaller
53 mins ago
Numbers, or digits? How do you arrive at that output?
– Kusalananda
40 mins ago
presumably only for numbers that occur more than once?
– Jeff Schaller
53 mins ago
presumably only for numbers that occur more than once?
– Jeff Schaller
53 mins ago
Numbers, or digits? How do you arrive at that output?
– Kusalananda
40 mins ago
Numbers, or digits? How do you arrive at that output?
– Kusalananda
40 mins ago
add a comment |
3 Answers
3
active
oldest
votes
This awk
script prints output as in your example:
awk '{
for ( i=1; i<=NF; i++ ) # loop over all fields/columns
dict[$i]++; # count occurrence in an array using the field value as index/key
}
END { # after processing all data
for (key in dict) # iterate over all array keys
if(dict[key]>1) # if the key occurred more than once
print dict[key] " : " key # print counter and key
}' inputfile
With the example input, the output is
2 : 10
3 : 12
2 : 34
If you remove the condition if(a[i]>1)
it will also list numbers that occurred only once.
add a comment |
You could use a pipeline
tr ' ' 'n' < datafile | sort | uniq -c
Forging on how refined you want your answer you could filter for numeric values or values where the count is more than one.
You could append| awk '($1 > 1) && ($2 > 0) { print $1 " : " $2 }'
to get output similar to the example in the question.
– Bodo
15 mins ago
add a comment |
Thanks people and for finish... increase the exit numbers in order?
Es. 3 : 12
2 : 10
2 : 34
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
});
}
});
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%2f502339%2fsed-grep-awk-operations%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
This awk
script prints output as in your example:
awk '{
for ( i=1; i<=NF; i++ ) # loop over all fields/columns
dict[$i]++; # count occurrence in an array using the field value as index/key
}
END { # after processing all data
for (key in dict) # iterate over all array keys
if(dict[key]>1) # if the key occurred more than once
print dict[key] " : " key # print counter and key
}' inputfile
With the example input, the output is
2 : 10
3 : 12
2 : 34
If you remove the condition if(a[i]>1)
it will also list numbers that occurred only once.
add a comment |
This awk
script prints output as in your example:
awk '{
for ( i=1; i<=NF; i++ ) # loop over all fields/columns
dict[$i]++; # count occurrence in an array using the field value as index/key
}
END { # after processing all data
for (key in dict) # iterate over all array keys
if(dict[key]>1) # if the key occurred more than once
print dict[key] " : " key # print counter and key
}' inputfile
With the example input, the output is
2 : 10
3 : 12
2 : 34
If you remove the condition if(a[i]>1)
it will also list numbers that occurred only once.
add a comment |
This awk
script prints output as in your example:
awk '{
for ( i=1; i<=NF; i++ ) # loop over all fields/columns
dict[$i]++; # count occurrence in an array using the field value as index/key
}
END { # after processing all data
for (key in dict) # iterate over all array keys
if(dict[key]>1) # if the key occurred more than once
print dict[key] " : " key # print counter and key
}' inputfile
With the example input, the output is
2 : 10
3 : 12
2 : 34
If you remove the condition if(a[i]>1)
it will also list numbers that occurred only once.
This awk
script prints output as in your example:
awk '{
for ( i=1; i<=NF; i++ ) # loop over all fields/columns
dict[$i]++; # count occurrence in an array using the field value as index/key
}
END { # after processing all data
for (key in dict) # iterate over all array keys
if(dict[key]>1) # if the key occurred more than once
print dict[key] " : " key # print counter and key
}' inputfile
With the example input, the output is
2 : 10
3 : 12
2 : 34
If you remove the condition if(a[i]>1)
it will also list numbers that occurred only once.
edited 37 mins ago
answered 42 mins ago
BodoBodo
1,645212
1,645212
add a comment |
add a comment |
You could use a pipeline
tr ' ' 'n' < datafile | sort | uniq -c
Forging on how refined you want your answer you could filter for numeric values or values where the count is more than one.
You could append| awk '($1 > 1) && ($2 > 0) { print $1 " : " $2 }'
to get output similar to the example in the question.
– Bodo
15 mins ago
add a comment |
You could use a pipeline
tr ' ' 'n' < datafile | sort | uniq -c
Forging on how refined you want your answer you could filter for numeric values or values where the count is more than one.
You could append| awk '($1 > 1) && ($2 > 0) { print $1 " : " $2 }'
to get output similar to the example in the question.
– Bodo
15 mins ago
add a comment |
You could use a pipeline
tr ' ' 'n' < datafile | sort | uniq -c
Forging on how refined you want your answer you could filter for numeric values or values where the count is more than one.
You could use a pipeline
tr ' ' 'n' < datafile | sort | uniq -c
Forging on how refined you want your answer you could filter for numeric values or values where the count is more than one.
answered 36 mins ago
roaimaroaima
44.8k756122
44.8k756122
You could append| awk '($1 > 1) && ($2 > 0) { print $1 " : " $2 }'
to get output similar to the example in the question.
– Bodo
15 mins ago
add a comment |
You could append| awk '($1 > 1) && ($2 > 0) { print $1 " : " $2 }'
to get output similar to the example in the question.
– Bodo
15 mins ago
You could append
| awk '($1 > 1) && ($2 > 0) { print $1 " : " $2 }'
to get output similar to the example in the question.– Bodo
15 mins ago
You could append
| awk '($1 > 1) && ($2 > 0) { print $1 " : " $2 }'
to get output similar to the example in the question.– Bodo
15 mins ago
add a comment |
Thanks people and for finish... increase the exit numbers in order?
Es. 3 : 12
2 : 10
2 : 34
add a comment |
Thanks people and for finish... increase the exit numbers in order?
Es. 3 : 12
2 : 10
2 : 34
add a comment |
Thanks people and for finish... increase the exit numbers in order?
Es. 3 : 12
2 : 10
2 : 34
Thanks people and for finish... increase the exit numbers in order?
Es. 3 : 12
2 : 10
2 : 34
answered 1 min ago
InsideMiamiTattooInsideMiamiTattoo
162
162
add a comment |
add a comment |
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%2f502339%2fsed-grep-awk-operations%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
presumably only for numbers that occur more than once?
– Jeff Schaller
53 mins ago
Numbers, or digits? How do you arrive at that output?
– Kusalananda
40 mins ago