LoginSignup
0

More than 1 year has passed since last update.

ファイルの先頭数バイトを削除したファイルを作成する

Last updated at Posted at 2023-02-01

S3に書き出したファイルが再生できないので先頭数バイトを落としたファイルを作成した話
ちなみに再生できないファイルはバイナリファイルでみたとき、先頭に不要なデータが 47byte あるような状態だった。

最初ddかなとおもってオプションを確認してできた。

dd if=source.webm of=dest.webm bs=1 skip=47

が、どうやらtailでもできるようだ。
ddはオプションが特殊なので、tailのほうが覚えやすい。

tail -c +48 source.webm > dest.webm

-c オプションが文字数というかバイト数指定しているのは知っていたが、+Kで指定することで先頭Kバイト目以降を表示することができる。知らなかった。

同様に -n オプションでも +K で先頭K行目以降を表示すると指定できる。

ちなみにPowerShell (5.1)では、以下のようにできた。

Get-Content -Path .\source.webm -Encoding Byte -Raw `
| Select-Object -Skip 47 `
| Set-Content -Path output.webm -Encoding Byte -NoNewline 

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0