I have a text file that contains (ANSI ?) escape sequences:
When I cat
the file I get formatted output:
How do I save / pipe the output of the text file to a new file so that the control codes are removed but the formatting is preserved?
In other words, I want to convert / export the contents of the file to a new file while retaining the intended display format (e.g. like one would get when using less -r <file>
).
I need an automated way to do this so that the output can be logged and sent as an email notification.
Here is the base64 output of the file in the above screenshots (use base64 -d
to decode it):
G1tIG1syShtbMTsxSA0KG1s0OzRIICAgICAgICAgICAgICAgICAgICAgICAgICBDT05GSURFTlRJ
QUwgSU5GT1JNQVRJT04bW0sbWzU7NEgbW0sbWzY7NEgbW0sbWzc7NEhUaGlzIHdvcmsgY29udGFp
bnMgdmFsdWFibGUsIGNvbmZpZGVudGlhbCwgYW5kIHByb3ByaWV0YXJ5IGluZm9ybWF0aW9uLhtb
SxtbODs0SERpc2Nsb3N1cmUsIHVzZSwgb3IgcmVwcm9kdWN0aW9uIGlzIGdvdmVybmVkIGJ5IHlv
dXIgTGljZW5zZSBBZ3JlZW1lbnQuG1tLG1sxMDs0SBtbSxtbMTE7NEhUaGlzIHVucHVibGlzaGVk
IHdvcmsgaXMgcHJvdGVjdGVkIGJ5IHRoZSBsYXdzIG9mIHRoZSBVbml0ZWQgU3RhdGVzIGFuZBtb
SxtbMTI7NEhvdGhlciBDb3VudHJpZXMuICBUaGUgd29yayB3YXMgY3JlYXRlZCBpbiAxOTg4IGFu
ZCByZXZpc2VkIGluIDE5OTQuICAbW0sbWzEzOzRISWYgcHVibGljYXRpb24gb2NjdXJzLCB0aGUg
Zm9sbG93aW5nIG5vdGljZSBzaGFsbCBhcHBseTobW0sbWzE0OzRIG1tLG1sxNTs0SBtbSxtbMTY7
NEggICBDb3B5cmlnaHQgMTk4OCwxOTk0LiBBbGwgcmlnaHRzIHJlc2VydmVkLhtbSxtbMTc7NEgb
W0sbWzE4OzRIG1tLG1sxOTs0SFRoaXMgQ29weXJpZ2h0IG5vdGljZSBhbmQgb3RoZXIgY29weXJp
Z2h0IG5vdGljZXMgaW5jbHVkZWQgaW4gdGhlIG1hY2hpbmUbW0sbWzIwOzRIcmVhZGFibGUgY29w
aWVzIG11c3QgYmUgcmVwcm9kdWNlZCBvbiBhbGwgYXV0aG9yaXplZCBjb3BpZXMuG1tLG1syMTs0
SBtbSxtbMjI7NEhUaGlzIGlzIGEgcmVnaXN0ZXJlZCB0cmFkZW1hcmsuG1tLDQo=
cat
it in a terminal emulator, select the text, copy it, and then paste it into another file. Alternatively, you can write a script which interprets just the escapes present in the file (clear
,cup
,el
), but it's not worth the trouble (just like doing research & evaluation for some already existing program doing that). – Jan 13 '21 at 06:13cat > outfile
and press Shift-Insert and Control-D to save it into another file. – Jan 13 '21 at 06:19How do I save / pipe the output of the text file to a new file so that the control codes are removed but the formatting is preserved?
- it's possibly only if byformatting
you mean indentation, paragraphs, whitespaces etc. – Arkadiusz Drabczyk Jan 13 '21 at 21:49