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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:40:05+00:00 2026-05-26T13:40:05+00:00

I am parsing text files looking for specific entries like so grep -e ‘Model’

  • 0

I am parsing text files looking for specific entries like so

grep -e 'Model' -e 'Manufacturer' -e 'Man Date' -e 'SW Version' -e' SW Name' -e 'HW Version' -e 'Receiver ID' JGMDTV356.HDD

This gives me an output like so

Model         = HR24
Manufacturer  = 100
Man Date      = 04/14/2010
SW Version    = 4D1
HW Version    = 2.3
Receiver ID   = 035635905389
Model         = WDCWD5000AVVS-63M8B0 (Dragonfly-0)

The problem is that some files do not have the same number of fields. How can I do something like this?

Model         = HR24
Manufacturer  = 100
Man Date      = N/A
SW Version    = 4D1
HW Version    = N/A
Receiver ID   = N/A
Model         = N/A

Could this be done?

  • 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-26T13:40:06+00:00Added an answer on May 26, 2026 at 1:40 pm

    As Matthew mentioned, what you are trying to do is beyond the intended use of grep. Awk was made for this type of thing and is available on most linux distros (gawk is the GNU implementation) and even many embedded Linux systems. There is a good tutorial for it here that will take under an hour and teach you pretty much all you need to know.

    Here is the awk code you will need to solve your problem:

    #!/bin/awk -f                                                                                             
    
    BEGIN {
        tokens["Model"] = 0
        tokens["Manufacturer"] = 0
        tokens["Man Date"] = 0
        tokens["SW Version"] = 0
        tokens["HW Version"] = 0
        tokens["Receiver ID"] = 0
    }
    
    {
        for (token in tokens){
            if ($1 == token){
                print $0;
                tokens[$1]++;
            }
        }
    }
    
    END {
        for (token in tokens){
            if( tokens[token] == 0){
                printf("%-13s = NA\n" , token)
            }
        }
    }
    

    Save this to a tmp.awk and add execute permissions to tmp.awk.

    cat <your file> | ./tmp.awk

    This will print out what you want.

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

Sidebar

Related Questions

I'm looking for a perfect text editor :) The must have list: vim-like modal
I'm pretty familiar with SSIS parsing of regular delimited text data files, however, I'm
I am reading about 600 text files, and then parsing each file individually and
I'm looking for a regular expression, but can't find. Parsing a text file looking
Parsing a text file in vb.net and need to locate the latitude and longitude
I have two arrays built while parsing a text file. The first contains the
I'm parsing text from a file and storing it in a string. The problem
I am parsing an input text file. If I grab the input one line
I am parsing text that has a heading and then data that applies to
Apart from just inserting and parsing text into a blank Word field, is there

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.