In this example, I mention that I have 2 lists.
list1
x;00:26:82:50:00:00;192.168.1.195;COMPUTER1
x;00:26:82:50:11:11;192.168.1.195;COMPUTER2
x;00:26:82:50:22:22;192.168.1.196;COMPUTER3
list2
x;00:26:82:50:11:11;192.168.1.197;COMPUTER3
And when I execute the command (thanks to ccs242):
for field in 2 3 4; do cut -d\; -f${field} list* | sort | uniq -d; done
I get duplicates
00:26:82:50:11:11
192.168.1.195
COMPUTER3
Now, I want to automate this process using a bash script, so if it does not find duplicates, run a certain command, but if the script detects duplicate, aborts and leaves the duplicates in in /var/log/syslog
This is my script:
pathlist=/etc/doc
function duplicate(){
acls=`for field in 2 3 4; do cut -d\; -f${field} $pathlist/list* | sort | uniq -d; done`
if [ ${acls} == '' ]; then
echo OK
#run a command foo
else
echo "Duplicate Data. Abort. Check /var/log/syslog"
echo $acls >> /var/log/syslog
exit
fi
}
duplicate
The problem is here:
[ ${acls} == '' ]
How can i fix it?