bash – 来自Unix“script”命令的格式输出:删除退格,换行和删除的字符?

我正在尝试使用 script命令来记录交互式shell会话,以便我可以使用它来准备文档.

根据手册页:

Script places everything in the log file,including lineFeeds and
backspaces. This is not what the naive user expects.

我是天真的用户(通常不会在手册页中大喊大叫,这非常令人兴奋!),我想处理输出,以便删除退格,换行和删除的字符等.

例如,我运行一个脚本会话:

stew:~> script -f scriptsession.log
Script started,file is scriptsession.log
stew:~> date
Mon Aug 22 15:00:37 EDT 2011
stew:~> #extra chars: that
stew:~> exit
exit
Script done,file is scriptsession.log

然后我用cat来读取会话日志:

stew:~> cat scriptsession.log
Script started on Mon 22 Aug 2011 03:00:35 PM EDT
stew:~> date
Mon Aug 22 15:00:37 EDT 2011
stew:~> #extra chars: that
stew:~> exit
exit

Script done on Mon 22 Aug 2011 03:01:01 PM EDT

但是当我少用时,我会看到使用cat看不见的不需要的字符的证据:

stew:~> less scriptsession.log
Script started on Mon 22 Aug 2011 03:00:35 PM EDT
stew:~> date
Mon Aug 22 15:00:37 EDT 2011
stew:~> #extra chars: thiESC[ESC[ESC[ESC[Kthat
stew:~> exit
exit

Script done on Mon 22 Aug 2011 03:01:01 PM EDT
scriptsession.log lines 1-8/8 (END)

当我使用cat时,我明白它不会删除不可见的字符,它只是不会明显地表示它们,就像少了 – 所以如果我将cat输出管道传输到文件,它仍然有不需要的字符.

我想要的输出格式是cat显示的副本.谢谢!

(如果这是重复的道歉,搜索“unix脚本输出格式”会返回大量关于手头问题的噪音结果!)

col命令将执行您正在寻找的一些(但不是全部)过滤. (例如,它似乎没有识别粗体和下划线的控制序列.)

我过去使用的一种方法是(a)更改我的shell提示符,使其不进行任何突出显示(通常会这样做),和/或(b)将$TERM设置为“哑”,以便各种命令赢得’尝试使用某些控制序列.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...