0

I've got a PDF expressed as an ASCII file of 0s and 1s, produced in the following way:

filepath="Manna.pdf"
data="$((echo obase=2; hexdump -ve'/1 "%u\n"' "${filepath}") | bc | xargs printf %08i)"
inputText="$(echo "${inputText}" | sed 's/\(.*\)/\L\1/')"
echo "${data}" > Manna.txt

How can this be converted back to PDF?

1 Answers1

1

I don't know why you'd want to do that, but perhaps you could use Perl's oct to convert each 8-bit binary substring into its numeric value and print that as a char:

perl -pe 's/([01]{8})/sprintf "%c", oct("0b$1")/ge'

Ex.

$ printf 'foo bar\nbaz\n' | 
    { echo obase=2; hexdump -ve'/1 "%u\n"' ; } | bc | xargs printf %08i | 
    perl -pe 's/([01]{8})/sprintf "%c", oct("0b$1")/ge'
foo bar
baz
steeldriver
  • 143,099
  • Magic, thanks for your help on that! cat "${filein}" | perl -pe 's/([01]{8})/sprintf "%c", oct("0b$1")/ge' > "${fileout}" does the trick. :) – BlandCorporation Sep 10 '19 at 15:03