当前位置:网站首页>diff 命令
diff 命令
2022-08-08 17:50:00 【滨边美波她男友】
问题描述
在使用 diff 命令对文件内容进行比对的时候,比对结果总是看起来云里雾里。如下:
[email protected]:~$ diff text.txt text1.txt
2,3c2,3
< 2222
< hhahaha
---
> 2222 dada
> hhahaha 312313
[email protected]:~$
解决方案:
diff 命令增加参数-u,可以输出差异上下文。如下:
[email protected]:~$ diff -u text.txt text1.txt
--- text.txt 2022-07-28 16:33:45.551384419 +0000
+++ text1.txt 2022-03-20 20:03:28.476004662 +0000
@@ -1,3 +1,3 @@
1111
-2222
-hhahaha
+2222 dada
+hhahaha 312313
可以看到,带负号的文本内容属于 text.txt,带正号的文本内容属于 text1.txt。
验证差异上下文的正确性:
[email protected]:~$ cat text.txt
1111
2222
hhahaha
[email protected]:~$ cat text1.txt
1111
2222 dada
hhahaha 312313
[email protected]:~$
更实用的命令:
上面执行:command:diff命令的-u参数很重要,使得差异输出中带有上下文。管道后面带有-N参数的:command:less命令(按字母q退出)会在输出的每一行前面添加行号,便于对输出结果进行说明。
[email protected]:~$ diff -u text.txt text1.txt | less -N
1 --- text.txt 2022-07-28 16:33:45.551384419 +0000
2 +++ text1.txt 2022-03-20 20:03:28.476004662 +0000
3 @@ -1,3 +1,3 @@
4 1111
5 -2222
6 -hhahaha
7 +2222 dada
8 +hhahaha 312313
[email protected]:~$
边栏推荐
猜你喜欢

mysql5.7安装教程(附下载链接)

grpc服务发现&负载均衡

How to set timed network disconnection to assist self-discipline in win10

orbslam2实验记录-----稠密建图

CF803F(容斥原理+莫比乌斯函数)

Open source summer | I have nothing to do during the epidemic, I made a button display box special effect to display my blog

医疗机构漏诊,该不该赔?--一起交通事故多处骨折,又遇到医疗机构漏诊

Tess4J OCR简单使用教程

前缀和的本质

Nioke 2022 Summer Multi-School 6 B Eezie and Pie (Difference on the tree + multiplication to find the kth ancestor board)
随机推荐
牛客多校第6场M(dp或者递推)
手机ETF基金开户哪家证券公司好?哪个更安全
高维前缀和和子集dp(状压dp的一种)
mysql5.7安装教程(附下载链接)
2.5W 字详解线程与锁了,面试随便问!!
Cholesterol-PEG-DBCO,CLS-PEG-DBCO,胆固醇-聚乙二醇-二苯基环辛炔一种环炔烃
CF1165F2(二分答案)
what‘s the meaning of xenial
Tensorflow教程(四)——MNIST项目入门
牛客2022 暑期多校6 B Eezie and Pie(树上差分 + 倍增求第 kth 祖先板子)
banner 如何显示drawable图片
poj1961 Period(KMP)
CF803F(容斥原理+莫比乌斯函数)
what‘s the meaning of build-essential
glide4入门
QT With OpenGL(泛光)(Bloom)
Open source summer | I have nothing to do during the epidemic, I made a button display box special effect to display my blog
并发与并行
CF187C(堆优化BFS)
js温度计插件自定义数值