Lets say I have the output of this command saved to a file.
cat /dev/urandom | tr -dc '[:graph:]' | fold -w 1000 | perl -pe 's/(.)(?=.*?\1)//g' | head -n 50
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.
glenn, yes the first instance of a four character string/key/token. I also needed the matching to be variable so I can manipulate the character matching as needed.
wildcard, this worked wonderfully, thank you.
thrig, this worked wonderfully, thank you.