파일 비교를 위해 cli 도구를 사용하고 출력 줄 앞에 줄 번호가 필요합니다. 라인 차이로 이동할 수 있습니다. :line-number: regular line contents
그래서 시도했지만 diff
문서를 읽는 것이 가능할 것 같습니다.
-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
있습니까? 그렇다면 어떻게?
답변
네 가능합니다. 이 옵션을 사용하는 경우 기본값은 모든 줄을 인쇄하는 것입니다. 이것은 매우 장황하며 원하는 것이 아닙니다.
diff --unchanged-line-format=""
변경되지 않은 행을 제거하므로 이제 이전 및 새 행만 생성됩니다.
diff --unchanged-line-format="" --new-line-format=":%dn: %L"
이제 앞에 새 줄 :<linenumber>:
과 공백을 표시하지만 여전히 이전 줄을 인쇄합니다. 당신이 그것들을 제거하고 싶다고 가정하면,
diff --unchanged-line-format="" --old-line-format="" --new-line-format=":%dn: %L"
새 줄 대신 오래된 줄을 인쇄하려면 바꾸십시오.