2 Diff Lines
tengel edited this page 2024-09-05 07:43:21 -05:00

One liner to diff lines one by one (handy for ldd output)

#!/bin/sh

diff --unchanged-line-format="" \
  --old-line-format="%dn: %L" \
  --new-line-format="%dn: %L" \
  "$1" "$2" | sort -n

# This is handy for situations where you need a line-by-line
# comparison of two similar outputs, such as ldd against two
# different libraries to find out if one of them is different
# (extra dependencies). For example:
#
# ldd libsomething.so.old | sort > old.txt
# ldd libsomething.so.new | sort > new.txt
#
# diffl.sh old.txt new.txt
# 1:  /usr/lib64/ld-linux-x86-64.so.2 (0x00007f61ba4c7000)
# 1:  /usr/lib64/ld-linux-x86-64.so.2 (0x00007f6b96d6b000)
# 2:  libc.so.6 => /usr/lib/libc.so.6 (0x00007f61b89f2000)
# 2:  libc.so.6 => /usr/lib/libc.so.6 (0x00007f6b95092000)
# 3:  libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f61b8376000)
# 3:  libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f6b94a16000)
# ...