Good morning,
I have many blocks of data, containing anywhere from 1 to 8 variables (denoted "CONDx" below) based on user input. I have written a script using awk and grep to extract data to be presented in a column format. This data I have extracted from a larger file, so maybe I need to go a step back for my solution. Anyways, the data looks like this:
> cat file
foo
REF Data1
COND1 Value1
COND2 Value2
foo
REF Data2
COND3 Value3
foo
REF Data3
COND1 Value4
COND3 Value5
foo
My script presents the results in the following column format, which I need to manually modify in the vertical direction to have it line up correctly:
COND1 COND2 COND3 COND4 COND5 COND6 COND7 COND8
Data1 Value1 Value2 Value3 x x x x x
Data2 Value4 Value5
Data3
My question is, is it possible using awk (or sed, whatever) to check if each CONDx is contained in each REF block, if it is print the corresponding "ValueX", and if it is not, print an "x" (or even better a blank) as a placeholder? So the desired output would be:
COND1 COND2 COND3 COND4 COND5 COND6 COND7 COND8
Data1 Value1 Value2 x x x x x x
Data2 x x Value3 x x x x x
Data3 Value3 x Value5 x x x x x
For COND1 for example, part of the script contained:
grep COND1 file | awk '{print $2} END { if (!NR) print "x" }' > temp.cond1
temp.cond1 to be pasted in the resultant file, but this only prints an "x" in the first row as seen in my output, I understand why it doesn't work, but can't think of new way. I think maybe it's possible to do with an IF statement perhaps? Would appreciate any help.
Thanks for your time.