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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:37:50+00:00 2026-06-04T18:37:50+00:00

I need to process a big data file that contains multi-line records, example input:

  • 0

I need to process a big data file that contains multi-line records, example input:

1  Name      Dan
1  Title     Professor
1  Address   aaa street
1  City      xxx city
1  State     yyy
1  Phone     123-456-7890
2  Name      Luke
2  Title     Professor
2  Address   bbb street
2  City      xxx city
3  Name      Tom
3  Title     Associate Professor
3  Like      Golf
4  Name
4  Title     Trainer
4  Likes     Running

Note that the first integer field is unique and really identifies a whole record. So in the above input I really have 4 records although I dont know how many lines of attributes each records may have. I need to:
– identify valid record (must have “Name” and “Title” field)
– output the available attributes for each valid record, say “Name”, “Title”, “Address” are needed fields.

Example output:

1  Name      Dan
1  Title     Professor
1  Address   aaa street
2  Name      Luke
2  Title     Professor
2  Address   bbb street
3  Name      Tom
3  Title     Associate Professor

So in the output file, record 4 is removed since it doen’t have the “Name” field. Record 3 doesn’t have Address field but still being print to the output since it is a valid record that has “Name” and “Title”.

Can I do this with awk? But how do i identify a whole record using the first “id” field on each line?

Thanks a lot to the unix shell script expert for helping me out! 🙂

  • 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-04T18:37:52+00:00Added an answer on June 4, 2026 at 6:37 pm

    This seems to work. There are MANY ways you could do this, even in awk.

    I’ve spaced it out for easier reading.

    Note that record 3 doesn’t show up because it’s missing an “Address” field, which you identified as required.

    #!/usr/bin/awk -f
    
    BEGIN {
            # Set your required fields here...
            required["Name"]=1;
            required["Title"]=1;
            required["Address"]=1;
    
            # Count the required fields
            for (i in required) enough++;
    }
    
    # Note that this will run on the first record, but only to initialize variables
    $1 != last1 {
            if (hits >= enough) {
                    printf("%s",output);
            }
            last1=$1; output=""; hits=0;
    }
    
    # This appends the current line to a buffer, followed by the record separator (RS)
    { output=output $0 RS }
    
    # Count the required fields; used to determine whether to print the buffer
    required[$2] { hits++ }
    
    END {
            # Print the final buffer, since we only print on the next record
            if (hits >= enough) {
                    printf("%s",output);
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read text data from big file line by line. But I need to
Imagine you have a big file stored in hdtf which contains structured data. Now
I need to process the incoming predefined ASN format data(coming from verity of clients
I'm writing a CMS in ASP.NET/C#, and I need to process things like that,
I need to create a process with integrity level high, so that it can
I have a large number of HTML files that I need to process with
what is better? I need to process data in several steps and it appears
Using C++ (and Qt), I need to process a big amount of 3D coordinates.
I need to process a HTML content and replace the IMG SRC value with
I need to process DICOM formatted medical images and visualize them in 3D, also

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.