加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-16 01:08:44 所属栏目:安全 来源:网络整理
导读:我正在尝试使用 script 命令来记录交互式shell会话,以便我可以使用它来准备文档. 根据手册页: Script places everything in the log file,including linefeeds and backspaces. This is not what the naive user expects. 我是天真的用户(通常不会在手册页
我正在尝试使用 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设置为“哑”,以便各种命令赢得’尝试使用某些控制序列.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读