![sed를 사용하여 diff 출력 병합](https://linux55.com/image/63924/sed%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20diff%20%EC%B6%9C%EB%A0%A5%20%EB%B3%91%ED%95%A9.png)
파일을 다음과 비교하면 다음과 같은 결과가 나옵니다 diff
.
< IF-Name :STRING: "lns-wall-01-t2" Index:Gge32: 260
---
> IF-Name :STRING: "lns-wall-01-t2" Index:Gge32: 25
다음 출력이 필요합니다.
lns-wall-01-t2 old:260 new:25
sed를 사용하고 싶습니다.
답변1
그리고 awk
:
awk '
/^</ { old = $NF }
/^>/ { str = $4 ; gsub(/"/,"",str) ; printf "%s old:%s new:%s\n", str, old, $NF }
' your_files_list_here
답변2
sed '
/^</{
# first line formatting
s/^.*"\(.*\)".*: /\1 old:/
# append next 2 lines
N
N
# exchange from 2nd line begining till last ":" by "new"
s/\n---.*: / new:/
}' "$Rep_Scripts"/diff.txt
답변3
다양한 유형의 diff 출력을 사용합니다.
diff -y --suppress-common-lines f1 f2
이는 보다 사용자 친화적인 형식을 제공합니다.
F-Name :STRING: "lns-wall-01-t2" Index:Gge32: 260 |IF-Name :STRING: "lns-wall-01-t2" Index:Gge32: 25
그리고
diff -y ........ |
perl -nE '/"(.*?)".*?32:\s*(\d+).*32:\s*(\d+)/
and say "$1 old:$2 new:$3"'