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

Clash 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.
shell cat
 |Â
show 2 more comments
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.
shell cat
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 filecat.cand figure it out yourself - all the rules appear to be in a nested conditional starting atif (show_nonprinting)
â steeldriver
Jul 13 at 1:07
1
... so for your particular input, where the128 + 32 <= ch < 128 + 127rule 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 usecat -vas the asciifier, it may be easier to useuuencodeand its inverse,uudecode, which will be lossless.
â Mark Plotnick
Jul 13 at 11:30
 |Â
show 2 more comments
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.
shell cat
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.
shell cat
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 filecat.cand figure it out yourself - all the rules appear to be in a nested conditional starting atif (show_nonprinting)
â steeldriver
Jul 13 at 1:07
1
... so for your particular input, where the128 + 32 <= ch < 128 + 127rule 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 usecat -vas the asciifier, it may be easier to useuuencodeand its inverse,uudecode, which will be lossless.
â Mark Plotnick
Jul 13 at 11:30
 |Â
show 2 more comments
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 filecat.cand figure it out yourself - all the rules appear to be in a nested conditional starting atif (show_nonprinting)
â steeldriver
Jul 13 at 1:07
1
... so for your particular input, where the128 + 32 <= ch < 128 + 127rule 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 usecat -vas the asciifier, it may be easier to useuuencodeand 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
 |Â
show 2 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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.cand figure it out yourself - all the rules appear to be in a nested conditional starting atif (show_nonprinting)â steeldriver
Jul 13 at 1:07
1
... so for your particular input, where the
128 + 32 <= ch < 128 + 127rule 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 -vas the asciifier, it may be easier to useuuencodeand its inverse,uudecode, which will be lossless.â Mark Plotnick
Jul 13 at 11:30