Artificial intelligent assistant

Remove adjacent lines that match pattern Input: file with sorted lines Output: file with 'unique' lines that match adjacent lines if we are to remove all digits Example Input abbylove2007 abbylove2008 abbylove2012 AbbyLove2014 abby1994lover abby2007lover abbylovesaal2018 abbylovesbsb2003 Output abbylove2007 abby1994lover Here abbylove2007 and abby1994lover are left since there are more than one adjacent line that matches abbylove\d+ and abby\d+lover

$ awk '{ curr=$0; gsub("[0-9]","",curr) } curr != prev { prev=curr; prevfull=$0; flag=0; next } !flag { print prevfull; flag=1 }' test
abbylove2007
abby1994lover


First, remove digits from the current line. If the result of this is different from the previous line with digits removed, then update the previous line with this line, remember the full previous line, and set the `flag` variable to zero, then continue with the next line.

The `flag` variable is used when outputting line that are the same as the previous line to make sure that we only output the _first_ of these lines.

For lines that are the same as the previous line (digits removed), if the flag isn't set, print the full previous line, then set the flag.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 741fc8d74a371032fc2cc2677b4abcc3