Reputation: 13
I want to plot box chart form file with has data already in two columns. Catch is that second column is in hex and need be additionality multiple by some const (734) i.e test.dat
amp 0x223
dupa 0x333
jasiu 0x4a4
halo 0xb1
best will be to do that in bash one liner . I just end with this
cat test.dat |xargs printf '%s $(printf "scale=2; %d/734\\n" | bc)\n' |xargs -0 echo
but that print some things like that
amp $(printf "scale=2; 547/734\n" | bc)
dupa $(printf "scale=2; 819/734\n" | bc)
jasiu $(printf "scale=2; 1188/734\n" | bc)
halo $(printf "scale=2; 177/734\n" | bc)
and not calculating second value. Last echo should do the work but is not doing , why and how to fix this ?
Upvotes: 1
Views: 65
Reputation: 48430
gnuplot
to the rescue!
plot "test.dat" using 0:($2/734.0):xtic(1) with boxes
Upvotes: 1
Reputation: 207660
Some late night fun...
Perl to the rescue! ;-)
perl -aE 'say $F[0] . " " . hex($F[1])/734' file
Upvotes: 1
Reputation: 67507
awk
to the rescue!
$ awk -P '{printf("%s %d\n", $1, $2*734)}' file
amp 401498
dupa 601146
jasiu 871992
halo 129918
convert 2nd field to decimal and multiply with 734. -P
is for POSIX mode, may disable many other useful features, however here anything else is not needed.
Upvotes: 2