Retrieve default value with grep -e?
I am parsing text files looking for specific entries like so
Code:
grep -e 'Model' -e 'Manufacturer' -e 'Man Date' -e 'SW Version' -e' SW Name' -e 'HW Version' -e 'Receiver ID' JGMDTV356.HDD Code:
Model = HR24 Code:
Model = HR24 |
Not (easily) with grep - anything with associative arrays (bash, awk, perl, ...) you should be able to do something. Maybe populate all as "n/a" and only print the input if found, else the default. If you don't want to hard-code the fields, make up a file containing them, and read it in.
|
An ugly hack using a bash script assuming that Model is always present and comes first and the other fields come in the same order if present.
Code:
#! /bin/bash Code:
Model = HR24 Quote:
|
Quote:
Ugly maybe, but this is a clever hack. Unfortunately, this won't fly. Depending on the supplier that sends the file, Model may not even be present. I need to devise a strategy where the relevant stuff is captured and the rest is rejected. Thanks for your time. |
In that case, I concur with syg00, grep is not the tool here, you need a proper prog lang (in my case Perl) that can handle arbitrary data layouts that may have missing elements.
|
All times are GMT -5. The time now is 05:58 PM. |