Saving output of a grep into a file with colors
|
I need to save the result of a grep command into a file, but I also want the output file to be formatted and keep the colors just like in the terminal. Is there a way to do that? Maybe make grep save to a some kind of markup language? If it is not possible, is there another tool that can accomplish this task? I am trying to make the search keyword stand out in the output file, exactly like it does in the terminal. |
|
Depending on what you're wanting to do with the output file, it's possible to add colors to normal text file, because the colors simply come from some special characters. Grep seems to not want to print them when you redirect it to a file, so you need to force it to:
Now, when you print the file to the console it will be printed with the colors, because Bash interprets those characters as "use this color".
However, if you open it in an editor like
The output looks right when I print it using
So if you're wanting to use an editor this probably isn't what you want. |
Saving output of a grep into a file with colors的更多相关文章
- grep的用法,小技巧,模板中含有\t时:grep -P "^\t" file
linux中grep和find的用法区别 本文章详细的介绍了关于在linux中的grep和find两个命令的用法介绍,以及后面总结了它们两年用法区别哦. 先我们来介绍一下关于grep用法和一些小注意事 ...
- grep:Binary file (standard input) matches
grep "key" xxx.log时输出 Binary file xxx.log matches 百度了一下:grep觉得这是二进制文件.解决方式:grep -a. grep - ...
- What makes grep consider a file to be binary?
grep -a worked for me: $ grep --help [...] -a, --text equivalent to --binary-files=text
- 转:Intellij idea Version Control File Status Colors ( 版本控制文件状态颜色 )
https://blog.csdn.net/Bruce_Lee__/article/details/80261308 Added —— 添加 Added in not active changelis ...
- Save output to a text file from Mac terminal
Simply with output redirection: system_profiler > file.txt Basically, this will take the output ...
- [Java in NetBeans] Lesson 17. File Input/Output.
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: We want to handle the bad Error. (e.g bad input / bugs in program) ...
- 【转载】Save terminal output to a file
To write the output of a command to a file, there are basically 10 commonly used ways. Overview: Ple ...
- grep 命令过滤配置文件中的注释和空行
grep 用法 Usage: grep [OPTION]... PATTERN [FILE]... Search for PATTERN in each FILE or standard input. ...
- Linux grep命令和正则表达式
介绍 grep是一个功能强大的文本搜索命令,可以用它来搜索某个文件中是否包含指定的搜索内容,它可以利用正则表达式来做复杂的筛选操作,它还可以为其它命令传输给管道的筛选,比如我们常用到的分析单个进程的操 ...
随机推荐
- ConcurrentHashMap以及HashMap,HashTable的区别
ConcurrentHashMap与HashMap,和HashTable 的区别? ConcurrentHashMap是一个线程安全的key-value数据结构,而HashMap不是.Concurre ...
- 红米.USB安装_无法打开
1.必须有 SIM卡,才能打开 USB安装 红米1s(miui8.5)就是这样 2. 3. 4. 5.
- Linux - xshell上传文件报错乱码
xshell上传文件报错乱码,解决方法 rz -be 回车 下载sz filename
- table+css与xhtmL+css实现同一登陆框(代码片段)
1.从网上下载了一个不错的登录框样式(table结合css布局): 2.初学xhtmL,自己改写了一下,希望有用 3. 我怎么不会上传截图呢? 1. [代码]xhtml_css组合 < ...
- AOP学习(2)
<property name="interceptorNames"> <!-- 相当于包MyMethodBeforeAdvice前置通知和代理对象关联,我们 也可 ...
- 循环递归+返回值(TreeView示例)
示例:获取TreeView的所有Node,保存到List<TreeNode>,封装到通用工具类: 方法一:使用static方法.属性---调用前清空static类型的List public ...
- Chrome_01_点击 Google搜索结果在新的页面打开
方法一:Ctrl + 左键 Chrome浏览器中,通过 Ctrl + 左键 ,是在新标签中打开的,通过 Shift + 左键 ,是在新窗口中打开的. 方法二: 1.登录 Google 2.进入下面的设 ...
- POJ-1741(树分治)
树的点分治 给出详细的讲解!!点这里打开论文-分治算法在树的路径问题中的应用 本题目是他讲的第一个例题: 我的理解:每次都找树的重心,计算以重心为根的子树之间所贡献的答案.不断这样下去:如果这棵树是一 ...
- curl常用命令行总结
curl 有时HTTP服务接口写完,需要验证下接口功能,这个使用用curl最合适了 curl 全称 command line url viewer curl www.taobao.com curl w ...
- linux命令学习笔记(12):more命令
more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示在屏幕上. more会以一页一页的显示方便 使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就 ...