#!/usr/bin/gawk -f ## This script will extract the which and tar rules from their files. BEGIN{ goWhich = 0; goTar = 0; FS=OFS="="; IGNORECASE = 1; } Pass=1 && /Stack after picking/{ goWhich = 1; next; } Pass=1 && goWhich && /=/{ sub ( /^ */, "" ); sub( /^AND/, "" ); FS=OFS="="; sub( / *$/, "", $1 ); rule = ""; rule = rule $1 ":"; sub( $1, "" ); sub( / *= */, "" ); sub( /^\[/, "" ); sub( /\]*$/, "" ); split( $0, str, "OR" ); for ( i in str ) { sub( / *\[/, "[", str[i] ); sub( /\] */, "]", str[i] ); sub( /\(.*\)/, "", str[i] ); rule = rule str[i] "," } sub( /,$/, "", rule ); gsub( / *: */, ":", rule ); gsub( / *, */, ",", rule ); sub( /^ */, "", rule ); sub( / *$/, "", rule ); print rule; } Pass=2 && /Treatments learnt/{ FS=OFS="["; goTar = 1; next; } Pass=2 && goTar && /=/{ sub( /.*worth=[0-9]*.[0-9]*/, "" ); for ( i = 2; i <= NF; i++ ) { sub( /\[/, "", $i ); sub( /\]/, "", $i ); sub( /=/, ":", $i ); sub( / *$/, "", $i ); print $i; } exit; } END{ print "END"; print ""; }