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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:43:51+00:00 2026-05-31T20:43:51+00:00

Again a SED question from me :) So, same as last time, I’m wrestling

  • 0

Again a SED question from me 🙂

So, same as last time, I’m wrestling with phone numbers. This time the problem is a bit different.
I this kind of organization currently in my text file:

Areacode:    List of phone numbers:
4444         NUM:111111  NUM:2222222 NUM:33333333
5555         NUM:1111111 NUM:2222    NUM:3333333  NUM:44444444 NUM:5555555

Now, every areacode can have unknown number of numbers, and also the phone numbers are not fixed in length.
What I would like to know, is how could I combine areacode and phone number, to look something like this:

4444-111111, 4444-2222222, 4444-33333333

My first idea was to add again a line break before each phone number and to match these sections with regex, and then just add the first remembered item to second, and first to third:

\1-\2, \1-\3, etc

But of course since sed can only remember 9 arguments, and there can be more than 10 numbers in one line this doesn’t work. Moreover, also non-fixed list of phone numbers made this a no go.
I’m again looking primarily the SED option, as I’ve been trying to get proficient with it – but more efficient solutions with other tools are of course definitely welcome!

  • 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-31T20:43:53+00:00Added an answer on May 31, 2026 at 8:43 pm
    $ cat input.txt | sed '1d;s/NUM:/ /g' | awk '{for(i=2;i<=NF;i++)printf("%s-%s%s", $1, $i, i==NF?"\n":",")}'
    4444-111111,4444-2222222,4444-33333333
    5555-1111111,5555-2222,5555-3333333,5555-44444444,5555-5555555
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Again I have a question regarding this plugin: http://t.wits.sg/2008/06/20/jquery-progress-bar-11/ What I want to achieve
Hello again ladies and gents! OK, following on from my other question on ASP.NET
again, this qn was from the practice qns in the mysql certification guide book
again a total newbie question from me about Haskell, and Leskah. (First, a subjective
Again me. I was using for a bit long time KohanaPHP and just can't
again, sorry for my silly question, but it seems that what i've learned from
Again i came back with a question. 1.I have a line drawing from a
Yet again, my teacher was unable to answer my question. I knew who may
Once again a very beginner-ish question, but here I go: I would like to
Me again... I have an XML File that contains different categories which I would

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.