Here is a Shell script that creates a table from as many user.js and prefs.js file as you want (the only arguments of the script):
#!/bin/sh
if [ -z "$1" ]
then
    printf "Usage: $0 prefs1.js ...
"
    exit
fi
printf '# key'
TMP=`mktemp -dt all_prefs.XXXXXX`
trap "rm -r $TMP 2>/dev/null" 0
keys=$TMP/$(seq -s " $TMP/" $#)
values=$TMP/$(seq -s ".val $TMP/" $#).val
mkfifo $TMP/keys $keys $values
grep '^ *user_pref *( *"' "$@" | cut -d \" -f 2 | sort -u | tee $keys > $TMP/keys &
for k in $keys
do
    printf "\t$1"
grep '^ *user_pref *( *"' "$1" | cut -d \" -f 2- | sed -e 's/" *, */'"$(printf \\t)"/ -e 's/ *) *; *$//' | sort -t "$(printf \\t)" -k 1,1 | join -t "$(printf \\t)" -a 1 -e undef -o 2.2 $k - > $k.val &
    shift
done
printf '
'
paste $TMP/keys $values
After a header, the script outputs one row per key, ordered alphabetically in the first column. There is one additional column per file (in the order they are given to the script). In such a column, the value is "undef" if the file does not define the key (present in at least one other file). Values are tab-separated. The script will work as long as the input files do not include any tab (\011). Supernumerary spaces anywhere in the input files should not raise any problem.

For the challenge (performance is not an issue here), I wrote the script above under a constraint: to not write anything to the disk. Only to pipes (and the final output is to the standard output, that you can redirect). As a consequence, all the commands executed in the two longest lines and the final 'paste' run in parallel.

If you (or somebody else) want(s) explanation about part of the script, I can answer.

Reply via email to