I have this file generated by me... i want to create some HTML output from it.
The problem is that i am really confused about how do I go about reading the file.
The file can continue this way as long as it wants. The A type (for that matter any type) might be repeated again too.
But there would always be 3 fields for a given type, Time, Result and ExpectedResult.
I need to consolidate all of these values for all the different types (A, B, etc.) and create a tabular report for them.
Oh, yes, forgot to mention.... I'm using a shell based on zsh.
Seems like a job for a higher-level code. Perl, python, awk, anything like that.
If the line can be very long you could expect unexpected problems (like storing too much data into a variable in shell or the line being truncated).
On the other side such trick could probably work as well: "for var in $(cat file); do .... done" or better - use "read".... you might need to play with the FS/IFS settings.
Anyway - I strongly suggest higher level language.
What does "consolidate" mean? What do you want to do with the line?
What type of output do you want?
Is this something like it:
printf "<table>\n"
while read a b line
do
eval "$line" ## set all the variables
printf "<tr><td>%s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s\n" \
"$a" "$b" "$ATime" "$AResult" "$AExpected" "$BTime" "$BResult" "$BExpected" \
"$CTime" "$CResult" "$CExpected"
done < "$FILE"
printf "</table>\n"
Use POSIX shell syntax for scripting; use extensions only when it is more efficient.
I read your code. I did think of something like that but it does not help me.
I guess I might have not been clear enough. The variables A,B,C,... could be of any number.
So i could have something ranging from A till maybe M (i.e. each A would have ATime, AResult, AExpected....... continuing like this all the way till MTime, MResult, MExpected)
Hope you follow...
AWK seems to be a good choice (however I have not analyzed the example in details). It seems like you are going to greate a table with cells spanning across multiple rows/columns. Think twice if this is what you need. Probably it would be acceptable to have the same fields repeated in multiple rows instead of using rowspan. That would make your code much easier.
You might need to count the entries first and then make a second run to fill the output document. Easy way is to parse that file 2x with a different code - however this is not optimal (low performance, too much I/O). That might be the best option for you.
There are plenty of other ways to do this (including PERL with "split" which can be very slow).
If by any chance you experience problems with number of "columns" in AWM try changing the awk (mawk, nawk, gawk,... there is plenty of this stuff with different limitations).