I try to create compare script using awk and another command and running successful.
But I think the script I create it's to long.
Is there anyone can shorten my script below ?
After plan A shorten the code than, plan B is :
1. I want eliminated a lot temp file (.txt), only need `lengkap.txt`
2. Put command in variable if can
It's my pleasure if anyone can help me
Below is the code that I create based searching and trying.#!/bin/bash
### Path Folder who will be compare ###
path1=/home/rio/apps1
path2=/home/rio/apps2
### Find all filename and convert to MD5 ###
find $path1 -type f | xargs md5sum > checksums.md5
find $path2 -type f | xargs md5sum > checksums2.md5
### Compare to find different folder ###
awk 'NR==FNR{c[$1]++;next};c[$1] == 0' checksums.md5 checksums2.md5 > hasil1.txt
awk 'NR==FNR{c[$1]++;next};c[$1] == 0' checksums2.md5 checksums.md5 > hasil2.txt
### Merge result of compare ###
awk '{print $0}' hasil1.txt hasil2.txt > perbedaan.txt
### Filter Just Filename Difference ###
cat perbedaan.txt | awk '{print $2}' > hasilperbedaan.txt
### File about result compare (just filename) ###
cekhasil=/home/rio/hasilperbedaan.txt
### Check if File result compare empty or not ###
if [ -s "$cekhasil" ]
then
echo " file exists and is not empty "
### Find All filename and date, after that put as we want ###
find $path1 -type f -ls | awk '{print $11" "$8" "$9" "$10 }' > filedate1.txt
find $path2 -type f -ls | awk '{print $11" "$8" "$9" "$10 }' > filedate2.txt
### Compare to get the date of filename ###
awk 'A[$1]++' hasilperbedaan.txt filedate1.txt > pre_hasil1.txt
awk 'A[$1]++' hasilperbedaan.txt filedate2.txt > pre_hasil2.txt
### Merge result of compare with date ###
awk '{print $0}' pre_hasil1.txt pre_hasil2.txt > lengkap.txt
else
echo " file does not exist, or is empty "
fi