Linux diff在输出中仅获得行号 [英] Linux diff get only line number in the output

查看:591
本文介绍了Linux diff在输出中仅获得行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用linux diff 命令获得以下输出:

I want to use linux diff command to get the following output:

2,4c2,4

我只想知道文件不同的行号。我不想要控制台上的实际行。

I only want to know the line numbers where the files are different. I don't want the actual line on the console.

例如:

如果我执行以下命令命令:
diff file1.txt file2.txt

If I will execute the following command: diff file1.txt file2.txt

我想要以下输出:

2,4c2,4

我不想要输出:

2,4c2,4
< I need to run the laundry.
< I need to wash the dog.
< I need to get the car detailed.
---
> I need to do the laundry.
> I need to wash the car.
> I need to get the dog detailed.

我经历了 diff 命令的手册但是我找不到任何可以实现我想要的选项。

I went through the manual of diff command but I wasn't able to find any option that would allow me to achieve what I want.

推荐答案

将其放置在 grep ,仅显示以数字开头的行。

Pipe it to grep and only show lines beginning with numbers.

diff file1.txt file2.txt | grep '^[1-9]'

这篇关于Linux diff在输出中仅获得行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆