Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6585533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:40:32+00:00 2026-05-25T16:40:32+00:00

I’m trying to use sed to drop strings containing repeated characters before appending them

  • 0

I’m trying to use sed to drop strings containing repeated characters before appending them to a file.
So far I have this, to drop stings with consecutive repetition like ‘AA’ or ’22’, but I’m struggling with full string repetition and incremental characters.

generic string generator | sed '/\([^A-Za-z0-9_]\|[A-Za-z0-9]\)\1\{1,\}/d' >> parsed sting to file

I also want to drop strings contain any repetition like ‘ABA’.
As well as, strings containing any ascending or descending characters like ‘AEF’ or ‘AFE’.

I’m assuming it would be easier to use multiple passes of sed to drop the unwanted strings.

** A little more information to try to avoid the XY problem mentioned. **

The character strings could be from 8 to 64 in length, but in this instance I’m focusing on 8. While at the same time I’ve restricted the string generation to only output an upper-case alpha string (A-Z). This is for a few reasons, but mainly that I don’t want the generated file to have a ridiculously huge footprint.

With the first pass of sed dropping unnecessary outputs like ‘AAAAAAAA’ and ‘AAAAAAAB’ from the stream. This results in the file starting with strings ‘ABABABAB’ and ‘ABABABAC’.

Next pass I want to check that from one character to the next doesn’t increase or decrease by a value of one. So strings like ‘ABABABAB’ would be dropped, but ‘ACACACAC’ would parse to the stream.

Next pass I want to drop strings that contain any repeated characters in the whole string. So strings like ‘ACACACAC’ would be dropped, but ‘ACEBDFHJ’ would parse to the file.

Hope that helps.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:40:33+00:00Added an answer on May 25, 2026 at 4:40 pm

    In order to do what you’re describing with sed, you’d need to run it many times. Since sed doesn’t understand the concept of “this character is incremental from this other character”, you need to run it across all possible combinations:

    sed '/AB/d'
    sed '/BC/d'
    sed '/CD/d'
    sed '/DE/d'
    

    etc.

    For descending characters, the same thing:

    sed '/BA/d'
    sed '/CB/d'
    

    In order to then drop strings with repeated characters, you can do something like this:

    sed '/\(.\).*\1/d'
    

    The following should do the trick:

    generic string generator |sed '/\(.\).*\1/d'|sed /BA/d|sed /AB/d||sed /CB/d|sed /BC/d|sed /DC/d|sed /CD/d|sed /ED/d|sed /DE/d|sed /FE/d|sed /EF/d|sed /GF/d|sed /FG/d|sed /HG/d|sed /GH/d|sed /IH/d|sed /HI/d|sed /JI/d|sed /IJ/d|sed /KJ/d|sed /JK/d|sed /LK/d|sed /KL/d|sed /ML/d|sed /LM/d|sed /NM/d|sed /MN/d|sed /ON/d|sed /NO/d|sed /PO/d|sed /OP/d|sed /QP/d|sed /PQ/d|sed /RQ/d|sed /QR/d|sed /SR/d|sed /RS/d|sed /TS/d|sed /ST/d|sed /UT/d|sed /TU/d|sed /VU/d|sed /UV/d|sed /WV/d|sed /VW/d|sed /XW/d|sed /WX/d|sed /YX/d|sed /XY/d|sed /ZY/d|sed /YZ/d
    

    I only tested this on a few input samples, but they all seemed to work.

    Note that this is quite ungainly, and would be better done by something a little more sophisticated than sed. Here’s a sample in python:

    import math
    def isvalid(x):
       if set(len(x)) < len(x):
         return False
       for a in range(1, len(x)):
         if math.fabs(ord(x[a])-ord(x[a-1])) == 1:
           return False
       return True
    

    This is much more readable than the giant set of sed calls, and has the same functionality.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want use html5's new tag to play a wav file (currently only supported
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.