How to convert visible control characters back to non-printing characters (opposite of 'cat -v')?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












Given the content of the file which was the result of cat -v conversion such as:



M-*M-;M-LM-]M-n


How can I convert back the file to the original binary format?




For example, given the following shell commands:



$ printf aabbccddee | perl -lne 'print pack "H*", $_' | cat -v > file
$ cat file
M-*M-;M-LM-]M-n


I'd like to do the opposite, so convert visible control characters to their original non-printing characters.







share|improve this question















  • 2




    I'm not sure you can reverse it, at least not losslessly. For example, if you have a file that contains a null byte, cat -v will output ^@. If you have a file with the characters ^@ in it, cat -v will output the same thing. If your file is longer than 64k, your odds of reconstructing it correctly are not good. Is an imperfect translation OK for your application?
    – Nick ODell
    Jul 12 at 22:48










  • Any ideas/tricks may help, doesn't need to be 100% lossless, as I'm doing that for obfuscation/education purposes.
    – kenorb
    Jul 13 at 0:27






  • 1




    Well at least for the GNU Coreutils implementation, you can read the source file cat.c and figure it out yourself - all the rules appear to be in a nested conditional starting at if (show_nonprinting)
    – steeldriver
    Jul 13 at 1:07






  • 1




    ... so for your particular input, where the 128 + 32 <= ch < 128 + 127 rule applies for every octet, you can simply add 128 to the ordinal value of the character e.g. ... cat -v | perl -lpe 's/M-(.)/sprintf "%.2x", 128 + ord($1)/ge'
    – steeldriver
    Jul 13 at 2:29










  • If you're not required to use cat -v as the asciifier, it may be easier to use uuencode and its inverse, uudecode, which will be lossless.
    – Mark Plotnick
    Jul 13 at 11:30














up vote
0
down vote

favorite












Given the content of the file which was the result of cat -v conversion such as:



M-*M-;M-LM-]M-n


How can I convert back the file to the original binary format?




For example, given the following shell commands:



$ printf aabbccddee | perl -lne 'print pack "H*", $_' | cat -v > file
$ cat file
M-*M-;M-LM-]M-n


I'd like to do the opposite, so convert visible control characters to their original non-printing characters.







share|improve this question















  • 2




    I'm not sure you can reverse it, at least not losslessly. For example, if you have a file that contains a null byte, cat -v will output ^@. If you have a file with the characters ^@ in it, cat -v will output the same thing. If your file is longer than 64k, your odds of reconstructing it correctly are not good. Is an imperfect translation OK for your application?
    – Nick ODell
    Jul 12 at 22:48










  • Any ideas/tricks may help, doesn't need to be 100% lossless, as I'm doing that for obfuscation/education purposes.
    – kenorb
    Jul 13 at 0:27






  • 1




    Well at least for the GNU Coreutils implementation, you can read the source file cat.c and figure it out yourself - all the rules appear to be in a nested conditional starting at if (show_nonprinting)
    – steeldriver
    Jul 13 at 1:07






  • 1




    ... so for your particular input, where the 128 + 32 <= ch < 128 + 127 rule applies for every octet, you can simply add 128 to the ordinal value of the character e.g. ... cat -v | perl -lpe 's/M-(.)/sprintf "%.2x", 128 + ord($1)/ge'
    – steeldriver
    Jul 13 at 2:29










  • If you're not required to use cat -v as the asciifier, it may be easier to use uuencode and its inverse, uudecode, which will be lossless.
    – Mark Plotnick
    Jul 13 at 11:30












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Given the content of the file which was the result of cat -v conversion such as:



M-*M-;M-LM-]M-n


How can I convert back the file to the original binary format?




For example, given the following shell commands:



$ printf aabbccddee | perl -lne 'print pack "H*", $_' | cat -v > file
$ cat file
M-*M-;M-LM-]M-n


I'd like to do the opposite, so convert visible control characters to their original non-printing characters.







share|improve this question











Given the content of the file which was the result of cat -v conversion such as:



M-*M-;M-LM-]M-n


How can I convert back the file to the original binary format?




For example, given the following shell commands:



$ printf aabbccddee | perl -lne 'print pack "H*", $_' | cat -v > file
$ cat file
M-*M-;M-LM-]M-n


I'd like to do the opposite, so convert visible control characters to their original non-printing characters.









share|improve this question










share|improve this question




share|improve this question









asked Jul 12 at 22:06









kenorb

7,29836196




7,29836196







  • 2




    I'm not sure you can reverse it, at least not losslessly. For example, if you have a file that contains a null byte, cat -v will output ^@. If you have a file with the characters ^@ in it, cat -v will output the same thing. If your file is longer than 64k, your odds of reconstructing it correctly are not good. Is an imperfect translation OK for your application?
    – Nick ODell
    Jul 12 at 22:48










  • Any ideas/tricks may help, doesn't need to be 100% lossless, as I'm doing that for obfuscation/education purposes.
    – kenorb
    Jul 13 at 0:27






  • 1




    Well at least for the GNU Coreutils implementation, you can read the source file cat.c and figure it out yourself - all the rules appear to be in a nested conditional starting at if (show_nonprinting)
    – steeldriver
    Jul 13 at 1:07






  • 1




    ... so for your particular input, where the 128 + 32 <= ch < 128 + 127 rule applies for every octet, you can simply add 128 to the ordinal value of the character e.g. ... cat -v | perl -lpe 's/M-(.)/sprintf "%.2x", 128 + ord($1)/ge'
    – steeldriver
    Jul 13 at 2:29










  • If you're not required to use cat -v as the asciifier, it may be easier to use uuencode and its inverse, uudecode, which will be lossless.
    – Mark Plotnick
    Jul 13 at 11:30












  • 2




    I'm not sure you can reverse it, at least not losslessly. For example, if you have a file that contains a null byte, cat -v will output ^@. If you have a file with the characters ^@ in it, cat -v will output the same thing. If your file is longer than 64k, your odds of reconstructing it correctly are not good. Is an imperfect translation OK for your application?
    – Nick ODell
    Jul 12 at 22:48










  • Any ideas/tricks may help, doesn't need to be 100% lossless, as I'm doing that for obfuscation/education purposes.
    – kenorb
    Jul 13 at 0:27






  • 1




    Well at least for the GNU Coreutils implementation, you can read the source file cat.c and figure it out yourself - all the rules appear to be in a nested conditional starting at if (show_nonprinting)
    – steeldriver
    Jul 13 at 1:07






  • 1




    ... so for your particular input, where the 128 + 32 <= ch < 128 + 127 rule applies for every octet, you can simply add 128 to the ordinal value of the character e.g. ... cat -v | perl -lpe 's/M-(.)/sprintf "%.2x", 128 + ord($1)/ge'
    – steeldriver
    Jul 13 at 2:29










  • If you're not required to use cat -v as the asciifier, it may be easier to use uuencode and its inverse, uudecode, which will be lossless.
    – Mark Plotnick
    Jul 13 at 11:30







2




2




I'm not sure you can reverse it, at least not losslessly. For example, if you have a file that contains a null byte, cat -v will output ^@. If you have a file with the characters ^@ in it, cat -v will output the same thing. If your file is longer than 64k, your odds of reconstructing it correctly are not good. Is an imperfect translation OK for your application?
– Nick ODell
Jul 12 at 22:48




I'm not sure you can reverse it, at least not losslessly. For example, if you have a file that contains a null byte, cat -v will output ^@. If you have a file with the characters ^@ in it, cat -v will output the same thing. If your file is longer than 64k, your odds of reconstructing it correctly are not good. Is an imperfect translation OK for your application?
– Nick ODell
Jul 12 at 22:48












Any ideas/tricks may help, doesn't need to be 100% lossless, as I'm doing that for obfuscation/education purposes.
– kenorb
Jul 13 at 0:27




Any ideas/tricks may help, doesn't need to be 100% lossless, as I'm doing that for obfuscation/education purposes.
– kenorb
Jul 13 at 0:27




1




1




Well at least for the GNU Coreutils implementation, you can read the source file cat.c and figure it out yourself - all the rules appear to be in a nested conditional starting at if (show_nonprinting)
– steeldriver
Jul 13 at 1:07




Well at least for the GNU Coreutils implementation, you can read the source file cat.c and figure it out yourself - all the rules appear to be in a nested conditional starting at if (show_nonprinting)
– steeldriver
Jul 13 at 1:07




1




1




... so for your particular input, where the 128 + 32 <= ch < 128 + 127 rule applies for every octet, you can simply add 128 to the ordinal value of the character e.g. ... cat -v | perl -lpe 's/M-(.)/sprintf "%.2x", 128 + ord($1)/ge'
– steeldriver
Jul 13 at 2:29




... so for your particular input, where the 128 + 32 <= ch < 128 + 127 rule applies for every octet, you can simply add 128 to the ordinal value of the character e.g. ... cat -v | perl -lpe 's/M-(.)/sprintf "%.2x", 128 + ord($1)/ge'
– steeldriver
Jul 13 at 2:29












If you're not required to use cat -v as the asciifier, it may be easier to use uuencode and its inverse, uudecode, which will be lossless.
– Mark Plotnick
Jul 13 at 11:30




If you're not required to use cat -v as the asciifier, it may be easier to use uuencode and its inverse, uudecode, which will be lossless.
– Mark Plotnick
Jul 13 at 11:30















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f454992%2fhow-to-convert-visible-control-characters-back-to-non-printing-characters-oppos%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f454992%2fhow-to-convert-visible-control-characters-back-to-non-printing-characters-oppos%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

The Forum (Inglewood, California)

Palaiologos