是否可以在并排差异输出中显示行号?
我将 diff 与 -y
和 --suppress-common-lines
选项一起使用,输出几乎完美,除了我想查看更改的行号。
示例:
file1:
line a
line b
line c
file2:
line a
line B
line c
line d
命令和输出:
$ diff -y --suppress-common-lines file1 file2
line b | line B
> line d
这种选项组合是否可以通过 diff 实现,还是我需要其他工具?
I am using diff with the -y
and --suppress-common-lines
options and the output is almost perfect except I'd like to see the line numbers of the changes.
Example:
file1:
line a
line b
line c
file2:
line a
line B
line c
line d
command and output:
$ diff -y --suppress-common-lines file1 file2
line b | line B
> line d
Is this combination of options possible with diff or do I need another tool?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,
-y
选项在内部使用格式化样式(与--LFMT-line-format
一样),您无法使用-y
累积格式化命令>。您无法从格式化参数中获取
-y
的作用,因此无法直接使用diff
解决问题(我检查了 diff 3.2 源代码)。您需要使用另一个工具。
Unfortunately the
-y
option uses the formatting style internally (as does--LFMT-line-format
), you cannot cumulate formatting commands with-y
.You cannot obtain from formatting parameters what
-y
does, so you cannot workaround directly withdiff
(I checked diff 3.2 source code).You need to use another tool.
如果您总是比较具有相同行号的行,则可以使用如下所示的内容:
当 awk 处理第一个文件时,
FNR
(记录的文件编号)等于NR
文件。next
语句跳到下一条记录。If you are always comparing lines with the same line numbers, you can use something like this:
FNR
(file number of record) is equal toNR
when awk is processing the first file. Thenext
statement skips to the next record.