0

I have below commands for extracting only the lines that will all consecutive duplicates two or more times I want to edit these sed and perl commands to exclude the first and the second character from the end of a line from being duplicated.

perl -lne 'print if /^((.)\2+(?!\2))+$/' 
sed -Ee '/^((.)\2+)+$/!d' input.txt

I want to print only the lines with all consecutively repeated characters except the last one or the last two characters in the same line. Non consecutively repeating characters are allowed, but only if 1st or 2nd from the end of a line of my big text file.

For example input file contains:

111224
447758
1122323
15225168
55226565

The output file should contain:

111224    (only last character is not consecutively repeated)
447758    (only the last two characters are not consecutively repeated)

Thanks

  • Hello roaima I mean that non consecutive duplicates are allowed only at the first or the second character from the end. – Ahmed Oct 23 '18 at 17:00
  • Which sentence is it ok now? – Ahmed Oct 23 '18 at 17:11
  • Your first sentence. I think it's missing a couple of words and a full stop somewhere - it feels like two half sentences crashed together. – roaima Oct 23 '18 at 17:33
3

Based on my answer from a previous question:

sed -En 'h;:a;s/^(.)\1+//;ta;/^.{1,2}$/{x;p}' file
  • @ glenn jackman thank you for your answer. But how to exclude the first or the second character from the Start of the line from being consecutive duplicated? – Ahmed Oct 23 '18 at 17:43
  • 1
    You are solidly in the "do my job for me" territory: Please see: Why is “Can someone help me?” not an actual question? – glenn jackman Oct 23 '18 at 17:58
  • Dear glenn jackman there is a difference between who want to depend on others and who want to benefit from their experiences. – Ahmed Oct 23 '18 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.