0

When using script to save all of the terminal output, I see strange characters in the saved files, such as [K, [0m, [KM, [C to name a few. While I cat or more the file I don't seem to see this, it's the saved file that I share with others so I like to know if there's a way to not include them without hacks.

$ script --version
script from util-linux 2.27.1
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:        16.04
Codename:       xenial

$ script -a foo.log

Saved file content:

Script started on Tue 10 Oct 2017 08:31:04 AM PDT
npasta@pasta-p50:~/link/marinara/periodic_sweetfish/201710_sweetfish$ 
(reverse-i-search)`': [K
[49@npasta@pasta-p50:~/link/marinara/periodic_sweetfish/201710_sweetfish$[C
[Knpasta@pasta-p50:~/link/marinara/periodic_sweetfish/201710_sweetfish$ cd pickles_ogre4_log_20171010083250_
_v0.0.7/
npasta@pasta-p50:~/link/marinara/periodic_sweetfish/201710_sweetfish/taptwo_ogre4_log_20171010083250_v0.0
0.7$ ll
total 1.2G
drwxrwxr-x 4 npasta npasta 4.0K Oct 10 08:36 [0m[01;34m..[0m/
drwxrwxr-x 3 npasta npasta 4.0K Oct 10 08:35 [01;34m.[0m/
-rw-rw-r-- 1 npasta npasta 122M Oct 10 08:33 ballers_sys.log.tgz_20171010083250
drwxrwxr-x 3 npasta npasta 4.0K Oct 10 08:32 [01;34mhome[0m/
-rw-r----- 1 npasta npasta 125M Oct 10 08:32 ballers.log.1_20171010083250
-rw-r----- 1 npasta npasta 3.3M Oct 10 08:32 ballers.log_20171010083250
-rw-r----- 1 npasta npasta  97M Oct 10 08:32 ballers.log.2_20171010083250
-rw-r----- 1 npasta npasta 154M Oct 10 08:32 ballers.log.3_20171010083250
-rw-r----- 1 npasta npasta 114M Oct 10 08:32 ballers.log.4_20171010083250
-rw-r----- 1 npasta npasta 114M Oct 10 08:32 ballers.log.5_20171010083250
-rw-r----- 1 npasta npasta 132M Oct 10 08:32 ballers.log.6_20171010083250
-rw-r----- 1 npasta npasta 157M Oct 10 08:32 ballers.log.7_20171010083250
-rw-r----- 1 npasta npasta  27M Oct 10 08:32 syslog.1_20171010083250
-rw-r----- 1 npasta npasta 736K Oct 10 08:32 syslog_20171010083250
-rw-r----- 1 npasta npasta  27M Oct 10 08:32 syslog.2_20171010083250
-rw-r----- 1 npasta npasta  27M Oct 10 08:32 syslog.3_20171010083250
-rw-r----- 1 npasta npasta  26M Oct 10 08:32 syslog.4_20171010083250
-rw-r----- 1 npasta npasta  27M Oct 10 08:32 syslog.5_20171010083250
-rw-r----- 1 npasta npasta  27M Oct 10 08:32 syslog.6_20171010083250
-rw-r----- 1 npasta npasta  27M Oct 10 08:32 syslog.7_20171010083250
npasta@pasta-p50:~/link/marinara/periodic_sweetfish/201710_sweetfish/taptwo_ogre4_log_20171010083250_v0.0
0.7$ M
(reverse-i-search)`': [K

[KM[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[Ca': cd taptwo_ogre4_log_20171010083250_v0.0.7/[5Pc': ack-grep -B 1 -A 1 -i "image wait" .
[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[1@k[C[C[C[1@-[C[C[C
npasta@pasta-p50:~/link/marinara/periodic_sweetfish/201710_sweetfish/taptwo_ogre4_log_20171010083250_v0.0
0.7$ ack-grep -B 1 -A 1 -i "image wait" .
[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[Kdisconnudisconnsdisconnbdisconn disconn[C[C[C[C[C[C[C" .
npasta@pasta-p50:~/link/marinara/periodic_sweetfish/201710_sweetfish/taptwo_ogre4_log_20171010083250_v0.0
0.7$ [H[Jnpasta@pasta-p50:~/link/marinara/periodic_sweetfish/201710_sweetfish/taptwo_ogre4_log_20171010083250_v0.0
0.7$ cd ..
npasta@pasta-p50:~/link/marinara/periodic_sweetfish/201710_sweetfish$ ls
20171001_auburnhills_proto4.log  [0m[01;35mIMG_20171001_133255.jpg[0m
20171001_auburnhills_proto5.log  [01;35mIMG_20171002_113137.jpg[0m
IsaacS
  • 175

1 Answers1

0

script saves the entire terminal history, including control characters so that things like color changes, backspaces, and title bar updates through terminal control sequences are preserved. When you cat them the control characters are interpreted by the terminal because they're not visible after the fact.

If you want to present the end result, you can try recreating the perl script shown in this relevant answer.

DopeGhoti
  • 76,081