Skip to main content
added 266 characters in body
Source Link
John1024
  • 76.4k
  • 12
  • 176
  • 165

To get a list of numbers that are repeated and eliminate all extra processes:

$ awk -F= '$1=="Global"{c[$2]++} END{for (num in c) if(c[num]>1)print num}' file.dat 33333 33337 

The above code uses = as a field separator. If the first field is Global, then we keep track in associative array c of the number of times that the second field, $2, has appeared in the file.

After the file has been read completely, we look through array c and print all numbers which had a count larger than 1.

Shorter version

As proposed by glenn jackman in the comments, we could simply print the number on its second appearance:

$ awk -F= '++c[$2] == 2 {print $2}' file.dat 33333 33337 

To get a list of numbers that are repeated and eliminate all extra processes:

$ awk -F= '$1=="Global"{c[$2]++} END{for (num in c) if(c[num]>1)print num}' file.dat 33333 33337 

The above code uses = as a field separator. If the first field is Global, then we keep track in associative array c of the number of times that the second field, $2, has appeared in the file.

After the file has been read completely, we look through array c and print all numbers which had a count larger than 1.

To get a list of numbers that are repeated and eliminate all extra processes:

$ awk -F= '$1=="Global"{c[$2]++} END{for (num in c) if(c[num]>1)print num}' file.dat 33333 33337 

The above code uses = as a field separator. If the first field is Global, then we keep track in associative array c of the number of times that the second field, $2, has appeared in the file.

After the file has been read completely, we look through array c and print all numbers which had a count larger than 1.

Shorter version

As proposed by glenn jackman in the comments, we could simply print the number on its second appearance:

$ awk -F= '++c[$2] == 2 {print $2}' file.dat 33333 33337 
deleted 295 characters in body
Source Link
John1024
  • 76.4k
  • 12
  • 176
  • 165

To get a list of numbers that are repeated:

$ grep -Po '(Global)=\K\d+' file.dat | sort | uniq -c | awk '$1>1{print $2}' 33333 33337 

Here, $1>2 selects those lines whose repetition counts are greater than one and print $2 prints the number which was repeated.

Or, you can get rid of the middlemen and just print the repeats directly using awkeliminate all extra processes:

$ awk -F= '$1=="Global"{c[$2]++} END{for (num in c) if(c[num]>1)print num}' file.dat 33333 33337 

The above code uses = as a field separator. If the first field is Global, then we keep track in associative array c of the number of times that the second field, $2, has appeared in the file.

After the file has been read completely, we look through array c and print all numbers which had a count larger than 1.

To get a list of numbers that are repeated:

$ grep -Po '(Global)=\K\d+' file.dat | sort | uniq -c | awk '$1>1{print $2}' 33333 33337 

Here, $1>2 selects those lines whose repetition counts are greater than one and print $2 prints the number which was repeated.

Or, you can get rid of the middlemen and just print the repeats directly using awk:

$ awk -F= '$1=="Global"{c[$2]++} END{for (num in c) if(c[num]>1)print num}' file.dat 33333 33337 

The above code uses = as a field separator. If the first field is Global, then we keep track in associative array c of the number of times that the second field, $2, has appeared in the file.

After the file has been read completely, we look through array c and print all numbers which had a count larger than 1.

To get a list of numbers that are repeated and eliminate all extra processes:

$ awk -F= '$1=="Global"{c[$2]++} END{for (num in c) if(c[num]>1)print num}' file.dat 33333 33337 

The above code uses = as a field separator. If the first field is Global, then we keep track in associative array c of the number of times that the second field, $2, has appeared in the file.

After the file has been read completely, we look through array c and print all numbers which had a count larger than 1.

Source Link
John1024
  • 76.4k
  • 12
  • 176
  • 165

To get a list of numbers that are repeated:

$ grep -Po '(Global)=\K\d+' file.dat | sort | uniq -c | awk '$1>1{print $2}' 33333 33337 

Here, $1>2 selects those lines whose repetition counts are greater than one and print $2 prints the number which was repeated.

Or, you can get rid of the middlemen and just print the repeats directly using awk:

$ awk -F= '$1=="Global"{c[$2]++} END{for (num in c) if(c[num]>1)print num}' file.dat 33333 33337 

The above code uses = as a field separator. If the first field is Global, then we keep track in associative array c of the number of times that the second field, $2, has appeared in the file.

After the file has been read completely, we look through array c and print all numbers which had a count larger than 1.