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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:37:10+00:00 2026-06-05T18:37:10+00:00

Trying to get this expression to work, can someone look at it and tell

  • 0

Trying to get this expression to work, can someone look at it and tell me how far off I am?

I’m trying to get info in line 1 to propagate to other blank lines.

Line 1 = "1234, type"
Line 2..99 = ", type"

Result: Line 1.. = “1234, type”

This is the expression

sed -i -R -n '{(^[^,]{});x;n;^,;s/^.{}/\1/;x;p;x;p}' SedExit.txt > Str.txt
  • 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-05T18:37:12+00:00Added an answer on June 5, 2026 at 6:37 pm

    Just in case you’re interested in an awk-based solution, and assuming my interpretation of your request in my comment above is correct:

    awk -F, 'BEGIN { OFS = "," } $1 { last = $1 } !$1 { $1 = last } { print }' SedExit.txt 
    

    EDIT: brief explanation –

    -F, tells awk to use comma as the input field separator; it will automatically split
    lines on comma and make the individual fields available as $1, $2, etc. ($0 is the whole line)

    BEGIN { code } runs the code in braces once at the beginning of the awk run, before any input is processed.

    OFS = "," sets the output field separator to comma, to match the input. That lets us modify the fields directly and still get comma-separated output, instead of having to reconstruct the whole line in our code.

    The rest of the code is run once per line of input:

    $1 { last = $1 } The first $1 is a condition that must be met for the next block of code to be executed: if that field of the current line is true (non-empty), then the block is run. The block saves a copy of that field in a new variable called `last’.

    So if there’s anything before the first comma, we remember it for later use.

    !$1 { $1 = last } The condition here is negated, so this block will only run if the first field is empty. In that case, we copy the other way, and set the first field to the value of last. Hopefully we have previously seen a line that matched the first block and set last to something, or this is not useful.

    { print } There’s no condition here, so the code is run on every line, and it just prints it out. The output will incorporate our modification to $1, if applicable.

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

Sidebar

Related Questions

I'm trying to get this expression to work, I'm pretty sure its not the
I'm trying to get the pipe (OR) to work. I have this regular expression
Trying to get this to work, with no luck: [DataMember] public Type ParameterType {
I'm trying to get this css layout to work with IE7 and I'm a
I've been trying to get this module to work and no matter what I've
I'm having a bit of trouble trying to get this quicksort algorithm to work
Im trying to get this working but for some reason it's just not right.
Been trying to get this up and running for a while now. Basically i
I'm trying to get this sitemap clas s working. It appears to use LINQ,
I am trying to get this awesome JQuery plugin working with SQL Server. I

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.