1

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 ?

3
  • Please provide a complete example! Where is anything related to gnuplot ? Commented Mar 1, 2018 at 22:04
  • I made mistake in description , value have to be divided by const not multiply , and result should be with precision of two places after dot/coma Commented Mar 2, 2018 at 6:46
  • That's why always post the expected output as well... Commented Mar 2, 2018 at 11:34

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes , it is what is in description , but I made mistake in description should be "...additionality divided by some const " additionally with precision of two places after dot/coma with is done in my script by printf "scale=2; 547/734\n" | bc. Of courese Your solution is what is currently in description and thanks for that, this is some clue
@SebastianMikulski Just change * to / and %d to %.2f
1

Some late night fun...

Perl to the rescue! ;-)

perl -aE 'say $F[0] . " " . hex($F[1])/734' file

Comments

1

gnuplot to the rescue!

plot "test.dat" using 0:($2/734.0):xtic(1) with boxes

1 Comment

@MarkSetchell Just found out, that gnuplot parses the hex data correctly without any hacks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.