Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
to give you more information about the file itself. I have had these characters in files in the past also, but only when I copied a file from Windows to Linux.
Executing
It might be worth telling us what's producing that output. The only thing I can think of (and only because I was reading another thread about this earlier today) is if you're running ls and that's aliased to `ls --color=always` somewhere, vim won't know what to do with the escape sequences that cause text to be colored, but cat will.
Also, dos2unix probably won't help. This is a Linux program producing the output, no? And besides, I wasn't aware dos2unix did anything besides convert CR/LF line terminators to LF.
This happens when you use the script command, the output file (default typescript) is exactly like what you're describing. I don't have any strange settings at all, that's just how it is.
Quote:
file typescript
typescript: ASCII text, with CRLF, LF line terminators, with escape sequences
Your problem is impossible to solve completely. It has been asked many times before in connection with the script command and terminal spying programs. What you have is the sequence of bytes that went to the terminal; what you want to get is a text version of what appeared on the terminal. That is fundamentally impossible; the terminal is a dynamic device while your text file is static.
As long as nothing complex happened in the terminal session (switch to full screen mode followed by user interaction, command recall, command editing, title setting etc) then a "good enough" solution is possible -- filtering out the bytes that controlled colour, cursor position, rang bells etc -- which may render the text sufficiently readable for your purposes.
An alternative approach -- which has the advantage of not being fundamentally impossible -- would be to replay the captured bytes by feeding them to a terminal thus reproducing the session.
Best
Charles
Last edited by catkin; 08-02-2009 at 01:33 PM.
Reason: Typo
Yeah, when I read catkin's post and thought about what you were saying just now, I was going to suggest cat, also.
It would work, with redirection. It works for me, when using the typescript files.
Why are you using vi? Are you trying to edit the file? Or are you trying to view the file?
If you are only trying to view the file, then you can use "less -fr" and the color sequences will be put to use.
To remove the escape sequences, you can use this:
Code:
$ cat dobit.sh
#!/bin/bash
#
# Copyright SwaJime's Cove, 2009; all rights reserved
#
# Based on data obtained from http://www.gnu.org/software/teseq/manual/html_node/Escape-Sequence-Recognition.html
#
# A control sequence starts with
CSI='\x1b\[' # the two-character csi escape sequence ‘Esc [’, followed by
Rp='[0-9:;<=>?]' # an optional sequence of parameter bytes in the range x30–x3F,
Ri='[- !\"#$%&'\''()*+,./]' # an optional sequence of intermediate bytes in the range x20–x2F,
Rf='[]@A-Z[\\^_`a-z{|}~]' # and a final byte in the range x40–x7e.
# The set of standard control sequence functions are defined in Ecma-48 / ISO/IEC 6429.
ls --color=always > myFile.txt
cat myFile.txt | sed -e 's/'"$CSI$Rp"'*'"$Ri"'*'"$Rf"'//g'
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.