Your description doesn't match your output, so I am a bit confused. Based on your description, the expected output should be:
818522;"Joey"; 817399;"Ron"; 817400; 818000;"ODC"; You wouldn't print any of the 890021 lines because they are last, so they will never have a different first field than the next line. If this is indeed what you want, you can do this:
$ awk -F';' '{ if($1!=last && prevLine){ print prevLine } { last=$1; prevLine=$0 } }' file 818522;"Joey"; 817399;"Ron"; 817400; 818000;"ODC"; If you also want to add an exception for the last bunch of lines, try something like this:
$ awk -F';' '{ if($1!=last && prevLine){ print prevLine; lastPrinted=last } { last=$1; prevLine=$0 } } END{ if($1 != lastPrinted){ print } }' file 818522;"Joey"; 817399;"Ron"; 817400; 818000;"ODC"; 890021;"monica" The idea is quite straightforward: if the first field is not the same as last and the prevLine variable is defined (so we don't print the first line), then we print the previous line (prevLine) and save the first field of the previous line (last) in the variable lastPrinted.
Then, for all lines, we set last to the 1st field and prevLine to the current line. Finally, when we reach the end of the file (END{}) we print the line if its 1st field is different from the 1st field we last printed for (lastPrinted).