On Tue, 2020-11-17 at 08:05 -0700, Assaf Gordon wrote: > > Hello, Hi,
> uniq supports the "--group" option, which adds a blank line after > each > group of identical lines - this can be used down-stream to process > groups in any way you want. But there is no way to have it remove the repeated lines also, correct? By down-stream process, I feel like you are leaving it up to the down- stream to remove the duplicate lines as well as add the "repeated %s times" messages. Is that correct? If so, uniq really adds no value. The down-stream might as well just do the adjacent line comparison also in such a case. > And with counting: > > $ cat in | uniq --group=append \ > | awk 'BEGIN { c = 0 } ; > $0=="" { print "Group has " c " lines" ; c=0 ; next } ; > 1 { print ; c++ }' > first line > Group has 1 lines > second line > Group has 1 lines > repeated line > repeated line > repeated line > repeated line > repeated line > Group has 5 lines > third line > Group has 1 lines This still doesn't really achieve the original stated goal as the repeated lines are not being replaced by your "Group has %d lines". I think once you add the repeated line suppression, you will see that adding a simple adjacent line comparison and just not using uniq at all is only slightly incrementally more in the down-stream (which is now the main). Cheers, b.
signature.asc
Description: This is a digitally signed message part