Remove the leading 0xff of a file

Curious that this question don’t actually raise any simple response on the internet because this is a common situation when you dump the full flash of a microcontroller and only want to keep the useful part of the file. To do that I use this command:

sed -i -e "$ s/\xff*$//" file.bin

The first $ make the execution of the next command only for the last line of the file to avoid removing 0xff in the middle of the file. The s/\xff*$// is a usual substitute command that replace all the consecutive 0xff before the end of the line by nothing.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s