How do I send data from one command block to another
Solution 1:
testforblock <position: x y z > <tileName: Block> [dataValue: int]
testforblock will check for a block and the command execution will succeed if it finds the correct block. otherwise it will fail so you would have to make the second command executing conditional on the first one succeeding.
A method to do this is to make replaceitem a conditional command block. which would only make it execute after testforblock found whatever it is you were checking for.