I run the following in the command line:
prog1 | prog2
The output (say, X) of above is a 4-digit hex number, e.g. FA34.
prog1 is a java program which reads data every 100ms on the serial. prog2 is the cut command which cuts out a portion I need. This works fine and I can see the desired value every 100ms on the standard out.
What I want:
prog1 | prog2 | <convert X to decimal> | <multiply by 2>
How to do this, using pipes or not, in the command line in one-go?
Note: I wrote a bash script to convert X to decimal and multiply by 2. But I couldn’t direct X into my script as an argument.
Here’s a funny possibility:
This echos
iscale=16first (to tellbcto consider user’s input in radix 16). Thensedappends*2to each line and all this goes through bc for the conversion to decimal and multiplication by 2.There’s a limitation: your program
prog2must output all the hexadecimal numbers in upper case (e.g.,FA34notfa34). If this is a limitation, use:instead.