ファイルの一部の比較

ファイルの一部の比較

ファイルが5つあります。

file1 - 32 bytes
file2 - 32 bytes
file3 - 32 bytes
file4 - 32 bytes

file5 - 128 bytes

データが一致しているかどうかを比較したい

file1 - first 32 bytes of file5
file2 - 2nd 32 bytes of file 5 i.e from 32- 64 bytes
file3-  3rd 32 bytes of file 5 i.e from 64-96 bytes 
file4-  4th 32 bytes of file5 i.e from 96 -128 bytes

以下を使用して最初の32バイトを比較できます。

cmp -n 32 file1.txt file5.txt

しかし、他の3つのデータ比較に従いますか?誰でも私を助けることができますか?

ベストアンサー1

  • そしてdd

ブロックをスキップして部品を抽出します。

 dd bs=32 count=1 skip=1 if=file5 | diff - file2

他のファイルと一致するようにスキップしたブロックの数を適切に増やします。

  • そしてsplit

ファイルが小さく、スペースがあまりありません。大きな部分を複数の部分に分けて比較します。

split -b 32 file5
diff xab file2
  • 一度に

たぶん、すべて一致するのでしょうか?もちろん、どちらか一方が一致しない場合、これは失われます。

 cat file{1..4}  | diff  - file5

もちろんcmp「diff」を変えることも可能です。

おすすめ記事