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 6029899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:57:21+00:00 2026-05-23T04:57:21+00:00

I am not sure if I can do this purely with sed: I am

  • 0

I am not sure if I can do this purely with sed:

I am trying to rearrange lines like this

GF:001,GF:00012,GF:01223<TAB>XXR
GF:001,GF:00012,GF:01223,GF:0666<TAB>XXXR3

to

GF:001<TAB>XXR
GF:00012<TAB>XXR
GF:01223<TAB>XXR
GF:001<TAB>XXXR3
GF:00012<TAB>XXXR3
GF:01223<TAB>XXXR3
GF:0666<TAB>XXXR3

Anyone any hints? The cardinality of GF:XXXX is alternating as the length of GF:XXXX is.

I am stuck with sed -n '
'/\(XX.*\)$/' {
s/,/\t\1\n/
}' input
but I cannot reference to the originally matched pattern in the first place. any ideas? cheers!

Update:
I think it is not possible to do this with just using sed. So I used perl to do this:

perl -e 'open(IN, "< file");
while (<IN>) {
    @a = split(/\t/);
    @gos = split(/,/, $a[0]);
    foreach (@gos) {
      print $_."\t".$a[1];
    }
close( IN );' > output

But if anyone knows a way to solve this just with sed please post it here…

  • 1 1 Answer
  • 1 View
  • 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-23T04:57:22+00:00Added an answer on May 23, 2026 at 4:57 am

    It can be done in sed, though I probably would use Perl (or Awk or Python) to do it.

    I claim no elegance for this solution, but brute force and ignorance sometimes pays off. I created a file called, unoriginally, sed.script containing:

    /\(GF:[0-9]*\),\(.*\)<TAB>\(.*\)/{
    :redo
    s/\(GF:[0-9]*\),\(.*\)<TAB>\(.*\)/\1<TAB>\3@@@@@\2<TAB>\3/
    h
    s/@@@@@.*//
    p
    x
    s/.*@@@@@//
    t redo
    d
    }
    

    I ran it as:

    sed -f sed.script input
    

    where input contained the two lines shown in the question. It produced the output:

    GF:001<TAB>XXR
    GF:00012<TAB>XXR
    GF:01223<TAB>XXR
    GF:001<TAB>XXXR3
    GF:00012<TAB>XXXR3
    GF:01223<TAB>XXXR3
    GF:0666<TAB>XXXR3
    

    (I took the liberty of deliberately misinterpreting <TAB> to be a 5-character sequence instead of a single tab character; you can easily fix the answer to handle an actual tab character instead.)

    Explanation of the sed script:

    • Find lines with more than one occurrence of GF:nnn separated by commas (we do not need to process lines that contain a single such occurrence). Do the rest of the script only on such lines. Anything else is passed through (printed) unchanged.
    • Create a label so we can branch back to it
    • Split the line into 3 remembered parts. The first part is the initial GF information; the second part is any other GF information; the third part is the field after the <TAB>. Replace this with the first field, <TAB>, third field, implausible marker pattern (@@@@@), second field, <TAB>, third field.
    • Copy the modified line to the hold space.
    • Delete the marker pattern to the end.
    • Print.
    • Swap the hold space into the pattern space.
    • Remove everything up to and including the marker pattern.
    • If we’ve done any work, go back to the redo label.
    • Delete what’s left (it was printed already).
    • End of script block.

    This is a simple loop that reduces the number of the patterns by one on each iteration.

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

Sidebar

Related Questions

Not sure if I can explain this correctly, but I am trying to execute
I am not sure this can be done at all... Background: I am constructing
Not sure if you can do this, but I want to select the first
Not sure if yall can help this time, as I'm just using this particular
I am not sure if I can post this sort of question (apologies in
Not sure why I can't figure this out. When a user makes a selection,
Not sure if I can do it this way. I want to get current
Consider this example: zh_Hant_HK format = yy'年'M'月'd'日' ah:mm Not sure if you can see
Not sure why I'm getting this error and can't figure it out? The cycle
Hoping you can help as im not sure how to approach this. Cant seem

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.