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是一个功能强大的文本搜索命令,可以用它来搜索某个文件中是否包含指定的搜索内容,它可以利用正则表达式来做复杂的筛选操作,它还可以为其它命令传输给管道的筛选,比如我们常用到的分析单个进程的操 ...
随机推荐
- unigui中TUniDBEdit的OnEndDrag问题
非常奇怪,unigui中TUniDBEdit未发布OnEndDrag属性,包括其子类:TUniDBNumberEdit.TUniDBFormattedNumberEdit.而其他数据感知组件都有OnE ...
- Build Antlr4 projects with eclipse java project template.
from:https://shijinglu.wordpress.com/2015/01/22/build-antlr4-projects-with-eclipse-java-project-temp ...
- NULL 与空字符串
空字符串 '' 不占内存空间; NULL占一个字节的空间; 空字符串 的判断用 == <> NULL值用 is null ifnull();
- Spring4面向切面AOP
AOP(Aspect Oriented Programming)面向切面编程,通过预编译方式和运行期动态代理实现程序功能的横向多模块统一控制的一种技术.AOP是OOP的补充,是spring框架中的一个 ...
- spring MVC--配置注解
<context-param> 作用:该元素用来声明应用范围(整个WEB项目)内的上下文初始化参数 param-name 设定上下文的参数名称.必须是唯一名称 param-value 设定 ...
- 嵌套list的实例化
在LeetCode上遇到这样返回值 public class Solution { public List<List<Integer>> levelOrder(TreeNode ...
- WampServer 2.5设置外网访问/局域网手机访问(403 Forbidden错误解决方法)
安装好wamp后,想用手机通过局域访问电脑上wamp下的网页,结果出现如下提示. (403 Forbidden)错误 1.打开http.conf文件 2.找到下图中红色方框中的onlineofflin ...
- linux命令学习笔记(8):cp 命令
cp命令用来复制文件或者目录,是Linux系统中最常用的命令之一.一般情况下,shell会设置一个别名, 在命令行下复制文件时,如果目标文件已经存在,就会询问是否覆盖,不管你是否使用-i参数.但是如果 ...
- Android之ExpandableList扩展用法(基于BaseExpandableListAdapter)
1.简介 基于基于BaseExpandableListAdapter扩展的ExpandableList用法,现在网上流行的主要有两种:第一种是向BaseExpandableListAdapter传入两 ...
- BZOJ3812 清华集训2014 主旋律
直接求出强联通生成子图的数量较难,不妨用所有生成子图的数量减去非强联通的. 非强联通生成子图在所点后满足编号最小的点所在的强联通分量不是全集. 由于$n$很小,我们可以考虑状态压缩. 对于点集$S$, ...