A program which extracts the values you want to see shouldn't be hard to do, but you will have to edit the parameters.txt
file yourself and provide the values you want to see, and omit what you dont want to see. The script can only extract the values you offer. It can't do the editing. In order for scripts to work, the data types and format have to be consistent.
You need to use single words with no spaces, or use numeric values, in the values column:
HSN AsperPlan # would be good (camel case)
# The following types can be a problem for Linux:
CS 1 for non MBC
CHAP 6 for MBC
CHAP 11 for BCCH on OL
etc.
# Better would be CS_1_for_non_MBC, etc. (or camel case)
If you want to use 100
in place of Ranges
, then you will have to make those changes yourself, and give us (or yourself) a modified parameters.txt file to work from.
The field names in parameters.txt that are not found in CNAI_DUMP_RAW1.txt should be omited from parameters.txt.
---------- Post updated 01-05-15 at 07:42 AM ---------- Previous update was 01-04-15 at 11:17 PM ----------
First attempt in bash. Awk would be much faster I'm sure.
#!/bin/bash
###############################################################################
# Use these commands to strip carriage returns from input files
# sed -i 's|\r$||g' CNAI_DUMP_RAW1.txt
# sed -i 's|\r$||g' parameters.txt
###############################################################################
dumpfil="./CNAI_DUMP_RAW1.txt"
parmsfil="./parameters.txt"
outfil="./csv.out"
> $outfil
hdr=($(head -n 1 $dumpfil))
lnum=0
while read raw
do
lnum=$(( $lnum + 1 ))
[ $lnum -lt 3 ] && continue # skip header and row separators
while read parm1 parm2
do
fnum=0 # lookup actual values
for fld in ${hdr
[*]};
do
fnum=$(( $fnum + 1 ))
if [[ $fld == ${parm1,,} ]]; then # field headers are lower case
break
fi
done
cell=$(echo $raw | cut -d ' ' -f 4 2>&1)
act_val=$(echo $raw | cut -d ' ' -f $fnum 2>&1)
printf "%s,%s,%s,%s\n" "$parm1" "$parm2" "$cell" "$act_val" | tee -a $outfil
done < $parmsfil
done < $dumpfil
# output
# ------
# CCMIN,RANGES,RBR201A,100
# CCHPWR,33,RBR201A,33
# CCHPWR,30,RBR201A,33
# ATT,YES,RBR201A,YES
# CB,NO,RBR201A,NO
# CBQ,HIGH,RBR201A,HIGH
# ...
# ...
# etc.
# real 2m8.955s
# user 1m59.455s
# sys 0m12.274s