I have the following SED Code, that extracts a username along with their date of birth and displays it on one line. User name and date of birth are are two separate lines.

The issues is that hold buffer is not being over written each time a name is encountered and stored. sometimes it can show about 10 users properly, but sometimes it displays the same name (2 or 3 times). see current results.

sed -rn \  
    -e '/^Name:/{  
       s/Name: //

    -e '/DOB:/{
       }' $f

I thought code above would give me an output similar to:

Current Results

Tito Puente     8/21/1999  
Tito Puente     23/13/1967  
ARON BYRDMAN    6/24/1320  
JOE P. EARTHE   9/7/1961  
WISTON P. GREY  HEAVEN, NY 10121 DOB: Mem Status: Journeyman  
WISTON P. GREY  42/12/1949  

Sample Data

I have tried various options to no avail. does any have a clue?

  • It looks like you're depending on Local being on the same line as Name, and that's clearly not the case for all names. – muru Jun 24 at 0:38
  • true, when i run that command separately the proper output is given. – user68650 Jun 24 at 0:50
  • muru, you were on the Money! i added s/Local:.*// and s/Name: // to standardize the line! – user68650 Jun 24 at 2:25
  • Could you possibly post the expected results vs. the results you are currently getting. When I try your code, it delivers results on the same format that you show, but it's unclear whether this is what you expect or not. – Kusalananda Jun 24 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.