답변:
라인 순서를 그대로 유지 하는 스크립트 를 작성 했습니다 . 다음은 중요한 행의 주석이 달린 버전입니다.
# Strip all context lines
diff_lines="$(grep '^[><+-] ' | sed 's/^+/>/;s/^-/</')" || exit 0
# For each line, count the number of lines with the same content in the
# "left" and "right" diffs. If the numbers are not the same, then the line
# was either not moved or it's not obvious where it was moved, so the line
# is printed.
while IFS= read -r line
do
contents="${line:2}"
count_removes="$(grep -cFxe "< $contents" <<< "$diff_lines" || true)"
count_adds="$(grep -cFxe "> $contents" <<< "$diff_lines" || true)"
if [[ "$count_removes" -eq "$count_adds" ]]
then
# Line has been moved; skip it.
continue
fi
echo "$line"
done <<< "$diff_lines"
if [ "${line+defined}" = defined ]
then
printf "$line"
fi
sort
주먹을 통해 둘 다 전달하십시오 .