I have written a script to parse data from some files on a Solaris 10 system and send the output to a CSV formatted file. The code snipped i am using to pull the data is as follows....
src_line=$(sed -n "/^search_pattern$/{=;}" $file)
for i in $src_line
do
start_line1=$(( i + 9 ))
nawk -v startline1="$start_line1" '
BEGIN{i=0; printf "%s, %s, %s, %s, %s\n", "Header 1", "Header 2", "Header 3", "Header 4", "Header 5"}
NR>=startline1 {if ($2 ~ /^[0-9]/)
{if ($4 ~ /^[0-9]/)
{fld4=$4}
else{fld4=""}
if (i == 0)
{i=1; printf "%s, %s, %s, %s, %s\n", $2, fld4, $6, $8, $10}
else{i=0; printf "%s, %s, %s, %s, %s\n", $2, fld4, $6, $8, $10}}
else{exit}}' $file > results.csv
done
I use SED to find the pattern in the file and report back with a line number.
It is possible that there can be more than one match in a file and all matches must be processed. After the match is found i skip n line, 9 in this case. If the vaule of filed 2 is numeric then Fileds 2,4,6....n are printed, If not then i know i have reached the end of the table which i am pulling data from.
I am trying to find a soulution to use AWK entirely for the process above but so far i have had no luck.
I can get AWK to find the pattern match, but i am unable to get it to skip the 9 lines.
Below is a sample from of data from a file i am processing
Table Header
++++++++++++++++++++++++++++++++++++++++++++++
+ Data Desp +
++++++++++++++++++++++++++++++++++++++++++++++
+ + + AV +
+ + +++++++++++++++++++++++++++++++++
+ + + A + B + C + D +
+ Col + Pos + + + + +
++++++++++++++++++++++++++++++++++++++++++++++
+ 1 + 1 + 11 + 3 + 0.1 + 0.2 +
+ 2 + 2 + 13 + 3 + 0.1 + 0.3 +
+ 3 + 1 + 9 + 3 + 0.1 + 0.4 +
+ 4 + 2 + 5 + 3 + 0.1 + 0.5 +
+ 5 + 1 + 21 + 3 + 0.1 + 0.6 +
+ 6 + 2 + 8 + 3 + 0.1 + 0.1 +
+ 7 + 1 + 7 + 3 + 0.1 + 0.4 +
+ 8 + 2 + 18 + 3 + 0.1 + 0.6 +
+ 9 + 1 + 45 + 3 + 0.1 + 0.7 +
+ 10 + 2 + 6 + 3 + 0.1 + 0.0 +
++++++++++++++++++++++++++++++++++++++++++++++
PS daa should look like this when opens in a plain txt editor.
Regards
Denis.