Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
2 added 61 characters in body
source | link

With awk (mawk):

$ awk -F . '{COUNTS[$1]++} END{for(ct in COUNTS) {print ct " " COUNTS[ct]printf("%d "%d time(s)"\n", ct, COUNTS[ct])}}' test.txt
30 3 time(s)
24 3 time(s)
25 4 time(s)
26 1 time(s)
29 1 time(s)

The -F sets the field separator (FS) to ., other than that we go through all lines with the {COUNTS[$1]++}, using $1 as the part before the decimal separator (.) and keeping a record of how many times we encounter them in an array named COUNTS.

AdAt the end (END {}) we then dump what we found. As you can see the largest part is the output.

A bit more readable in a file:

{COUNTS[$1]++}
END {
  for(ct in COUNTS)
  {
    print ct " " COUNTS[ct]printf("%d "%d time(s)"\n", ct, COUNTS[ct])
  }
}

With awk (mawk):

$ awk -F . '{COUNTS[$1]++} END{for(ct in COUNTS) {print ct " " COUNTS[ct] " time(s)"}}' test.txt
30 3 time(s)
24 3 time(s)
25 4 time(s)
26 1 time(s)
29 1 time(s)

The -F sets the field separator (FS) to ., other than that we go through all lines with the {COUNTS[$1]++}, using $1 as the part before the decimal separator (.) and keeping a record of how many times we encounter them in an array named COUNTS.

Ad the end (END {}) we then dump what we found.

A bit more readable in a file:

{COUNTS[$1]++}
END {
  for(ct in COUNTS)
  {
    print ct " " COUNTS[ct] " time(s)"
  }
}

With awk (mawk):

$ awk -F . '{COUNTS[$1]++} END{for(ct in COUNTS) {printf("%d %d time(s)\n", ct, COUNTS[ct])}}' test.txt
30 3 time(s)
24 3 time(s)
25 4 time(s)
26 1 time(s)
29 1 time(s)

The -F sets the field separator (FS) to ., other than that we go through all lines with the {COUNTS[$1]++}, using $1 as the part before the decimal separator (.) and keeping a record of how many times we encounter them in an array named COUNTS.

At the end (END {}) we then dump what we found. As you can see the largest part is the output.

A bit more readable in a file:

{COUNTS[$1]++}
END {
  for(ct in COUNTS)
  {
    printf("%d %d time(s)\n", ct, COUNTS[ct])
  }
}
1
source | link

With awk (mawk):

$ awk -F . '{COUNTS[$1]++} END{for(ct in COUNTS) {print ct " " COUNTS[ct] " time(s)"}}' test.txt
30 3 time(s)
24 3 time(s)
25 4 time(s)
26 1 time(s)
29 1 time(s)

The -F sets the field separator (FS) to ., other than that we go through all lines with the {COUNTS[$1]++}, using $1 as the part before the decimal separator (.) and keeping a record of how many times we encounter them in an array named COUNTS.

Ad the end (END {}) we then dump what we found.

A bit more readable in a file:

{COUNTS[$1]++}
END {
  for(ct in COUNTS)
  {
    print ct " " COUNTS[ct] " time(s)"
  }
}