Search code examples
regexbashawkseddc

dc: '\' (0134) unimplemented


I'm using an obfuscation technique that involves dc. If you pipe a smaller line that doesn't involve a backslash, you get this.

root@revolt:~/Working/Bash# cat temp.text
[q]sa[ln0=aln256%Pln256/snlbx]sb806639340302927610462193083720snlbxq

root@revolt:~/Working/Bash# cat temp.text | dc
Hello world.

However if you try something larger like

root@revolt:~/Working/Bash# cat temp.text
[q]sa[ln0=aln256%Pln256/snlbx]sb331832177645759643350464573357407988278700985112761888842542077811521\
080128221484476741215560snlbxq

Where there ends up being a backslash on the line, this happens:

root@revolt:~/Working/Bash# cat temp.text | dc
dc: '\' (0134) unimplemented
Hel���t��root@revolt:~/Working/Bash# 

However, if you are to run this

root@revolt:~/Working/Bash# dc<<<[q]sa[ln0=aln256%Pln256/snlbx]sb331832177645759643350464573357407988278700985112761888842542077811521\
> 080128221484476741215560snlbxq
Hello world.
Hello world.
Hello world.

It works just fine. The above example is typing dc<<< and then copy and pasting the string WITH backslashes. Weird.

My questions are these:

  1. Is there a way to sed/cut/awk/etc. to remove the backslashes and put all the lines on a single line with no backslashes?

    or

  2. Is there a way to help dc interpret backslashes?


Solution

  • You can handle it using BASH string manipulation:

    s=$(<temp.txt)
    dc <<< "${s//\\[[:space:]]/}"
    Hello world.
    Hello world.
    Hello world.
    

    "${s//\\[[:space:]]/}" will remove all instances of \ followed by line break from file data.