I am using dd to return a stream of data from tape. I want to send this via a pipe that will extract the byte range I require. I need to check for the presence of a string in the initial bytes, and based on that value the byte range will differ. Something like this...
dd if=/dev/tape/st0 bs=512K | { var=1; if [[ $(head -c13) == "././@LongLink" ]]; then var=3; } | dd of=extracted_file.bin skip=$(512*$var) iflag=skip_bytes
However, I understand that a variable cannot be referenced after the pipe segment in which it is defined.
EDIT
Based on kusalananda's comment, I think the best way to achieve may actual goal is to restore a single block from the tape, get the info I need, then rewind and restore the whole file using dd and the calculated value for skip. This is because there doesn't seem to be any reliable way to remove bytes from the beginning of a file inplace (unlike for the end, where we have truncate)