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













2















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









share|improve this question

























  • 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
















2















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









share|improve this question

























  • 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














2












2








2








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









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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










3 Answers
3






active

oldest

votes


















4














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.






share|improve this answer

































    3














    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.






    share|improve this answer
























    • 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



















    0














    Thanks people and for finish... increase the exit numbers in order?
    Es. 3 : 12
    2 : 10
    2 : 34





    share























      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      4














      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.






      share|improve this answer






























        4














        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.






        share|improve this answer




























          4












          4








          4







          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.






          share|improve this answer















          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 37 mins ago

























          answered 42 mins ago









          BodoBodo

          1,645212




          1,645212

























              3














              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.






              share|improve this answer
























              • 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
















              3














              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.






              share|improve this answer
























              • 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














              3












              3








              3







              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.






              share|improve this answer













              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.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              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



















              • 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











              0














              Thanks people and for finish... increase the exit numbers in order?
              Es. 3 : 12
              2 : 10
              2 : 34





              share




























                0














                Thanks people and for finish... increase the exit numbers in order?
                Es. 3 : 12
                2 : 10
                2 : 34





                share


























                  0












                  0








                  0







                  Thanks people and for finish... increase the exit numbers in order?
                  Es. 3 : 12
                  2 : 10
                  2 : 34





                  share













                  Thanks people and for finish... increase the exit numbers in order?
                  Es. 3 : 12
                  2 : 10
                  2 : 34






                  share











                  share


                  share










                  answered 1 min ago









                  InsideMiamiTattooInsideMiamiTattoo

                  162




                  162






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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

                      Szabolcs (Ungheria) Altri progetti | Menu di navigazione48°10′14.56″N 21°29′33.14″E /...

                      Discografia di Klaus Schulze Indice Album in studio | Album dal vivo | Singoli | Antologie | Colonne...

                      How to make inet_server_addr() return localhost in spite of ::1/128RETURN NEXT in Postgres FunctionConnect to...