I had read the post on: bash - replace space with new line, but it does not helped to solve my issue.
[My Directory]
[root@testlabs Config]# ls
Archive Backup_Files
config_file.tgz
hostname1-config.uac
hostname2-config.uac
hostname3-config.uac
My-config_17Oct2014.tgz
non_extension-config_file1
non_extension-config_file2
[root@testlabs Config]#
I need to echo a list of MD5 Checksum results from a file. I am able to do so by doing this:
##IDENTIFY MD5 CHECKSUM##
//To output the md5sum of the original file with a correct format to a temp file [md5<space><space>file_name]
ls $FULL_FILE_NAME | md5sum $FULL_FILE_NAME > /tmp/md5sum.tmp
//To compare the md5sum of the orignal file with the md5sum of the backup copies in the archive directory
ls $CONFIG_ARCHIVE_DIR | grep -i --text $CONFIG_FILE_HOSTNAME-$FILE_TIMESTAMP.tgz | md5sum -c /tmp/md5sum.tmp >> /tmp/md5sum2.tmp
##COMPARING MD5 CHECKSUM##
if [ -s /tmp/md5sum2.tmp ];
then
echo ""
echo "Comparison of MD5 for files archived:"
echo '---------------------------------------'
/bin/sort -d /tmp/md5sum2.tmp
fi
and this will be the result when it was executed: (echo of the CONTENTS in /tmp/md5sum2.tmp)
Comparison of MD5 for files archived:
---------------------------------------
config_file.tgz: OK
hostname1-config.uac: OK
hostname2-config.uac: OK
hostname3-config.uac: OK
My-config_17Oct2014.tgz: OK
non_extension-config_file1: OK
non_extension-config_file1: OK
## WANTED ##
However I would like the result to be display in this way:
Comparison of MD5 for files archived:
---------------------------------------
- config_file.tgz: OK
- hostname1-config.uac: OK
- hostname2-config.uac: OK
- hostname3-config.uac: OK
- My-config_17Oct2014.tgz: OK
- non_extension-config_file1: OK
- non_extension-config_file2: OK
I tried doing this, (echo the CONTENTS of /tmp/md5sum2.tmp into /tmp/md5sum3.tmp with the '-' infront)
1)
##COMPARING MD5 CHECKSUM##
if [ -s /tmp/md5sum2.tmp ];
then
echo ""
echo "Comparison of MD5 for files archived:"
echo '---------------------------------------'
/bin/sort -d /tmp/md5sum2.tmp
for CONFIG_FILES in `/bin/cat /tmp/md5sum2.tmp`
do
/bin/sort -d /tmp/md5sum2.tmp | grep $CONFIG_FILES > /tmp/md5sum3.tmp
done
for MD5_COMPARE in $(/bin/sort -d /tmp/md5sum3.tmp)
do
echo -e " - $MD5_COMPARE\n"
done
fi
Result 1)
Comparison of MD5 for files archived:
---------------------------------------
- config_file.tgz:
- OK
- hostname1-config.uac:
- OK
- hostname2-config.uac:
- OK
- hostname3-config.uac:
- OK
- My-config_17Oct2014.tgz.tgz:
- OK
- non_extension-config_file1:
- OK
- non_extension-config_file2:
- OK
2)
for MD5_COMPARE in $(/bin/sort -d /tmp/md5sum3.tmp)
do
echo -n " - $MD5_COMPARE"
done
Result 2)
Comparison of MD5 for files archived:
---------------------------------------
- config_file.tgz: - OK - hostname1-config.uac: - OK - hostname2-config.uac: - OK -
hostname3-config.uac: - OK - My-config_17Oct2014.tgz: - OK - non_extension-config_file1: -
OK - non_extension-config_file2: - OK
/tmp/md5sum3.tmp
.$FULL_FILE_NAME
or$CONFIG_ARCHIVE_DIR
are. We also don't need to. We do need to know what the files you are comparing look like.