I read the question: Compare consecutive lines in awk / (or python) and randomly select one of the repeating lines . Now I have one more question: How do I change the code if I want to make this comparison not only for the x value, but also for the y value or more columns? Maybe something like
if ($1 != prev) && ($2 != prev) ???
In other words: I want to compare if the x value and y value of the current line match the x-value AND y-value of the next consecutive lines.
Data:
The result should look like this:
or (due to random selection)
Code from the above link, which does the stuff for x values, but NOT for y values ββin the AND condition:
$ cat tst.awk function prtBuf( idx) { if (cnt > 0) { idx = int((rand() * cnt) + 1) print buf[idx] } cnt = 0 } BEGIN { srand() } $1 != prev { prtBuf() } { buf[++cnt]=$0; prev=$1 } END { prtBuf() }
source share