I would like to compare only the first n characters on each line in a file and return only the first line containing the first instance of those characters.

So, for example, without having to sort the file, I'd like to look at the first four characters on every line in the file. I want to find the first instance of any four character string on each line and print only the lines containing the first instances.

I would appreciate it if the command could be modified to look at four, five, or six characters etc on each line.

Thank you very much for your time and assistance. I have really been struggling to figure this out.

MelBurslan, the content of the string should be irrelevant but the output of the above - now corrected - command is every character I can type on an English language keyboard. Below are two sample lines.