1

処理したいファイルのセットがあります。ファイルの作成または削除を制御することはできません。ただし、各ファイルの最後のバイトは常にxFFであり、未使用であることを私は知っています。

ファイルを処理し、最後のバイトを変更して、ファイルが処理されたことを確認したいと思います。シェルでシングルバイト演算の具体例を見つけることができません。

擬似コード

for file in *
do
if (lastbyteof($file) == xFF)
then
    # Process this file
    ...
    # Mark the file so we don't process it again
    lastbyteof($file) = xF0
fi
4

1 に答える 1

0

要件を最後のバイトから 4 番目に変更し、このように処理しました。改善や代替提案は大歓迎です。

for file in *.ts
do
    # Get the value of the fourth byte (skip the first 3)
    checkByte=`hexdump -n1 -s3 -e'"" 1/1 "%02xf"' "$file"`
    if [ $checkByte == "ff" ]
    then
        # Process this file

        # Change the fourth byte to 0xFE
        echo -ne \\xFE | dd conv=notrunc bs=1 count=1 seek=3 of="$file"
    fi
done
于 2013-03-10T21:08:40.107 に答える