Input:> printf 1\n\2\n3\n123Desired output:011Typing printf 1\n\2\n3\n | dc -e '-p' the output is:dc: stack emptydc: stack empty
How to get the difference between numbers using dc?
dc
You can pipe the entire set of commands directly to dc.printf 1 2 3 - - p | dcIf you'd like to subtract an arbitrary stack you can use a macro.printf %s [-z1<r]srz1<rp <insert numbers here> | dcSo for exampleprintf %s [-z1<r]srz1<rp 100 5 2 1 | dc96The macro does the following:[ Start macro- Subtract top two numbers and push back to stackz1<r Push stack size to stack and 1, then compare LESSTHAN, if true run r macro]sr End of macro, store in register rz1<r Check if stack contains elements by testing 1 < Stack Sizep Print result.`