My program creates two files with same name but different extension (for ex: 20162012.dat & 20162012.cnf). Sometimes the program fails to create .dat file. So the other .cnf file becomes orphan. I am looking for a script to compare this and delete the orphan .cnf file for which its partner .dat file is not present.
Any scripts and suggestions.. please help.
I tried below one but errors out.. may be I am missing something. please correct.
Script:
for f in *.cnf
do
[ -e "$f" ] || continue
f="${f%%.cnf}"
[ -e "$f".dat ] || rm -i -- "$f".cut
done
Error:
rm: cannot remove `20162010.cut': No such file or directory
Note: I am having the script and file to be compared and deleted in the same folder.
Thanks !
something.cnf
exists andsomething.dat
doesn't, you try torm something.cut
which is not the same assomething.cnf
.