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?
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:
Save this to a tmp.awk and add execute permissions to tmp.awk.
cat <your file> | ./tmp.awkThis will print out what you want.