There are 2 files has same structure.Output difference of each other columns, based on same value of specific column.
##!/bin/bash
set -e
result_dir='/home/folder1'
#2 test files
cat << EOF > $result_dir/old
1 a /home
5 b /home/me
6 e /home/me/file 2
3 c /home/oth
EOF
cat << EOF > $result_dir/new
1 a /home
4 b /home/me
6 f /home/me/file 2
5 c /home/oth/file
EOF
#loop
changed=()
while read -r -u 5 OWNER GROUP FOLDER; do
temp=''
while read -r -u 6 OWNER_NEW GROUP_NEW FOLDER_NEW; do
#exist in both old & new
if [[ "$FOLDER" == "$FOLDER_NEW" ]]; then
temp+=$FOLDER
if [[ $OWNER != $OWNER_NEW ]]; then
temp+=$sep$OWNER_NEW
else
temp+=$sep
fi
if [[ $GROUP != $GROUP_NEW ]]; then
temp+=$sep$GROUP_NEW
else
temp+=$sep
fi
#changed?
if [[ "$(echo -e "${temp}" | sed -e 's/[[:space:]]*$//')" != $FOLDER ]] ; then
changed+=($temp)
fi
break
fi
done 6<$result_dir/acl_folder_new
#old loop
done 5<$result_dir/acl_folder_old
echo -e "${changed[@]}"
Output as below:
/home/me 4
/home/me/file 2 f
Everything is ok, but speed too slow when file contain more than 10000+ lines as other post1,post2
How to nested loop 2 files then compare columns without using while read
?