Posts Tagged awk

styling gnuplot

So… I like gnuplot a lot, but out of the box, it looks terrible.

I mean it looks great as far as informational use, but not so great for the sexy, sexy.

I don’t really get that into it, but it doesn’t make the same splash as some goofier js toolkits, etc.

So… I went thru tons o’ dox, turned to svg terminal and did some minor post production work with a script

% for f in min max mean ; do grep -w ${f} test* ; done | awk '{print $NF > $1}'
% TITLE="Time Ranges by Test Run" XLABEL="Test Run" YLABEL="Time in Seconds" \
gello.sh min mean max 

That first crazy line gets the min,max and mean from the test file and splits each one out into a separate file (thx awk!)

SEXY!

Leave a Comment

Print the name of any class in a jar that has a main method:

Print the name of any class in a jar that has a main method:

jar="output/opennlp-tools-1.4.3.jar"
javap -classpath ${jar} $(     
    jar tf ${jar}      \
    | grep ass$        \
    | cut -f1 -d.      \
    | tr '[$/]' .      
) \ 
| tr '\n' '@'          \
| sed 's,}@,}=,g'      \
| tr '=' '\n'          \
| grep -w main         \
| tr '@' '\n'          \
| grep '^public class' \
| awk '{print $3}'

Leave a Comment

pretty column (field) printing with awk

You know what you have to do… you have to collect all the strings for every field, keep the max length for each column, then at the end spit them back out again.

But… you need to store each field for each row and awk only supports 1 dimensional arrays… suck it up and say the script only supports up to a max of 255 fields:

BEGIN {
	row = 0
	max_fields = 0;
	super_max = 255;
} {
	for ( i = 1 ; i <= NF ; i++ ) {
		idx = row + super_max * i;
		len = length( $i );
		data[ idx ] = $i;
		if ( len > max[ i ] ) {
			max[ i ] = len;
		}
	}
	if ( NF > max_fields ) {
		max_fields= NF;
	}
	row++;
} END {
	for ( r = 0 ; r < row ; r++ ) {
		for ( i = 1 ; i <= max_fields ; i++ ) {
			idx = r + super_max * i;
			fmt = "%-" max[ i ]  "s ";
			printf( fmt , data[ idx ], max[ i ]  );
		}
		printf( "\n" );
	}
}

columnbo.awk

Here is some prettified output:

this.logger            = logger;            
this.dataSourceFactory = dataSourceFactory; 
this.wsdlUrl           = wsdlUrl;           
this.wsdlKey           = wsdlKey;           
this.documentDAO       = documentDAO;   

Leave a Comment

sum,avg,min,max with awk

awk ‘BEGIN{count=0;sum=0;min=0;max=0} {n=$1 ; if (0==count||nmax) max=n; count++; sum+=n;} END {printf( “min: %d\nmax: %d\nsum: %d\ncnt: %d\navg: %f\n”, min,max, sum,count, sum/count );}’

Leave a Comment