perl - print only if value in field does not match previous line -
ok not sure gawk best tool here, if has easy way of doing using perl, sed, uniq glad use it. trying filter set of data looks this:
"1" "ari201304010" "sln" 1 0 0 1 "2" "ari201304010" "sln" 1 0 1 1 "3" "ari201304010" "sln" 1 0 1 3 "4" "ari201304010" "sln" 1 0 1 0 "5" "ari201304010" "sln" 1 0 2 1 "6" "ari201304010" "sln" 1 1 0 1 "7" "ari201304010" "sln" 1 1 0 0 "8" "ari201304010" "sln" 1 1 1 0 "9" "ari201304010" "sln" 1 1 2 2 "10" "ari201304010" "sln" 2 0 0 0
the 5th element can 1
or 0
. print every last occurance of value on 5th field. print if 5th field not mach value in line before.
i think awk right tool:
awk '$5 != last; {last = $5}' last=-1 input
note prints line 'if 5th field not match value in line before', not 'print every last occurrence of value'. not understand second last sentence in question, i'm ignoring since seems contradict last sentence of question.
if want print line if 5th field of next line different, try:
awk '$5 !=b && nr>1{print a} {a=$0; b=$5}' input
Comments
Post a Comment