首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >差-输出行号

差-输出行号
EN

Unix & Linux用户
提问于 2012-03-23 22:38:11
回答 1查看 40.9K关注 0票数 29

我想使用cli工具进行文件比较,并且需要输出行之前的行号,以帮助我跳到行差,因为我使用的工具可以理解在哪里跳转,如果行的开头类似于这个:line-number: regular line contents

因此,我尝试了diff,阅读文档似乎是可能的:

代码语言:javascript
复制
  -D, --ifdef=NAME                output merged file with `#ifdef NAME' diffs
      --GTYPE-group-format=GFMT   format GTYPE input groups with GFMT
      --line-format=LFMT          format all input lines with LFMT
      --LTYPE-line-format=LFMT    format LTYPE input lines with LFMT
    These format options provide fine-grained control over the output
      of diff, generalizing -D/--ifdef.
    LTYPE is `old', `new', or `unchanged'.  GTYPE is LTYPE or `changed'.
    GFMT (only) may contain:
      %<  lines from FILE1
      %>  lines from FILE2
      %=  lines common to FILE1 and FILE2
      %[-][WIDTH][.[PREC]]{doxX}LETTER  printf-style spec for LETTER
        LETTERs are as follows for new group, lower case for old group:
          F  first line number
          L  last line number
          N  number of lines = L-F+1
          E  F-1
          M  L+1
      %(A=B?T:E)  if A equals B then T else E
    LFMT (only) may contain:
      %L  contents of line
      %l  contents of line, excluding any trailing newline
      %[-][WIDTH][.[PREC]]{doxX}n  printf-style spec for input line number
    Both GFMT and LFMT may contain:
      %%  %
      %c'C'  the single character C
      %c'\OOO'  the character with octal code OOO
      C    the character C (other characters represent themselves)

但是,对于这种复杂的转换,没有任何例子或解释。

是否有可能从diff获得这样的输出?如果是的话,怎么做?

EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2012-03-24 02:36:32

是的,这是可能的。在使用这些选项时,默认的做法是打印出每一行。这是非常冗长的,不是你想要的。

代码语言:javascript
复制
diff --unchanged-line-format=""

将消除没有变化的行,所以现在只产生旧行和新行。

代码语言:javascript
复制
diff --unchanged-line-format="" --new-line-format=":%dn: %L"

现在将显示以:<linenumber>:和空格为前缀的新行,但仍然打印旧行。假设你想消灭他们,

代码语言:javascript
复制
diff --unchanged-line-format="" --old-line-format="" --new-line-format=":%dn: %L"

如果你想打印旧行而不是新行,那就把它们换一圈。

票数 55
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/34874

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档