Comparison two files using cmp bash command and sed option

73 Views Asked by At

I have simple script which is checking if file from today is different than file from yesterday. For that I am using cmp command, but unfortunately I need to also make some correction in file so I use sed option for that, however my script is not working as I expect and always show that file is different and I am sure that when sed is apply then file should be same.

#!/bin/bash

todayfile=$(date +%d%m%Y)
yesterdayfile=$(date -d "yesterday" +%d%m%Y)


echo "----- POLICY -----"
file1_in=$(sed 's|during_schedule=YES;|during_schedule=NO;|' /opt/custom_scripts/arch/policy_$todayfile.txt)
file2_in=$(sed 's|during_schedule=YES;|during_schedule=NO;|' /opt/custom_scripts/arch/policy_$yesterdayfile.txt)

file1="/opt/custom_scripts/arch/policy_$todayfile.txt"
file2="/opt/custom_scripts/arch/policy_$yesterdayfile.txt"

if cmp -s "$file1_in" "$file2_in"; then
    printf 'INFO: The file "%s" is the same as "%s"\n' "$file1" "$file2"
else
    printf 'ERROR: The file "%s" is different from "%s"\n' "$file1" "$file2"
fi
0

There are 0 best solutions below