Re: [dev] a suckless hex editor
On Fri, Nov 13, 2015 at 02:52:17PM -0500, Greg Reagle wrote:
> Okay then. It no longer depends on xxd. It depends on od for the hex dump
> (works with both GNU od and sbase od) and echo, awk, tr, cut for the reverse
> hex dump.
> #!/bin/sh
> [ -z "$1" -o -z "$2" ] && { echo "$0 infile outfile"; exit 1; }
> [ -z "$EDITOR" ] && { echo "\$EDITOR must be defined"; exit 1; }
>
> tmpfile=$(mktemp) || exit 1
> infile="$1"
> outfile="$2"
>
> od -Ax -tx1 "$infile" | head -n -1 > $tmpfile
> $EDITOR "$tmpfile"
> /bin/echo -ne $(tr -s ' ' < "$tmpfile" | cut -d' ' -f2-17 | awk '{for (i=1; i<=NF; i++) printf "\\x%s", $i}') > $outfile
> rm "$tmpfile"
echo -e is evil, use printf(1)
Received on Fri Nov 13 2015 - 20:54:35 CET
This archive was generated by hypermail 2.3.0
: Fri Nov 13 2015 - 21:00:17 CET