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

  • Home
  • SEARCH
  • 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 8408097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:32:56+00:00 2026-06-09T23:32:56+00:00

Specific question What is a shell command to turn strings like this class A(B,

  • 0

Specific question

What is a shell command to turn strings like this

class A(B, C):

into sets of strings like this

B -> A; 
C -> A;

Where A, B, and C are all of the form \w+ and, where I’ve written “B, C” I really mean any number of terms separated by commas and whitespace. I.e. “B, C” could equally be “B” or “B, C, D, E”.

Big picture

I’m visualizing the class hierarchy of a Python project. I’m looking into a directory for all .py files, grepping for class declarations and then converting them to DOT format. So far I’ve used find and grep to get a list of lines. I’ve done what is above in a small python script. If possible I’d like to use just the standard unix toolchain instead. Ideally I’d like to find another composable tool to pipe into and out of and complete the chain.

  • 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-06-09T23:32:57+00:00Added an answer on June 9, 2026 at 11:32 pm

    You want primitive? This sed script should work on every UNIX since V7 (but I haven’t tested it on anything really old so be careful). Run it as sed -n -f scriptfile infile > outfile

    : loop
    /^class [A-Za-z0-9_][A-Za-z0-9_]*(\([A-Za-z0-9_][A-Za-z0-9_]*, *\)*[A-Za-z0-9_][A-Za-z0-9_]*):$/{
    h
    s/^class \([A-Za-z0-9_][A-Za-z0-9_]*\)(\([A-Za-z0-9_][A-Za-z0-9_]*\)[,)].*/\2 -> \1;/
    p
    g
    s/\(class [A-Za-z0-9_][A-Za-z0-9_]*(\)[A-Za-z0-9_][A-Za-z0-9_]*,* */\1/
    b loop
    }
    

    Those are BREs (Basic Regular Expressions). They don’t have a + operator (that’s only found in Extended Regular Expressions) and they definitely don’t have \w (which was invented by perl). So your simple \w+ becomes [A-Za-z0-9_][A-Za-z0-9_]* and I had to use it several times, resulting in major ugliness.

    In pseudocode form, what the thing does is:

    while the line matches /^class \w+(comma-separated-list-of \w+):$/ {
        save the line in the hold space
        capture the outer \w and the first \w in the parentheses
        replace the entire line with the new string "\2 -> \1;" using the captures
        print the line
        retrieve the line from the hold space
        delete the first member of the comma-separated list
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope this doesn't fall into the non question category. I would like to
i have this specific question to do to you, i have a database from
This is a very specific question which will probably earn me the tumbleweed badge,
This is quite a specific question, and I have had no luck on the
This is a very specific question for a Google Chrome extension. http://www.meebo.com/mobile/ This page
This question is not necessarily Couchbase 2.0 develop preview specific however I think it
This seems to me like a very simple question, but I can't seem to
This is a more specific question to follow up on [another question that I
Very new to web programming still and I don't really have a specific question
This is a specific version of this question . I want to check if

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.