How to check if the merge of two files is successful?

Hi All,

I have a requirement to check if the merge of files is successful or not. The script to merge files goes like this,

cat Rewards_Header Rewards_Siebel_Notif_temp Rewards_Siebel_Remind105_temp > Rewards_Siebel

Sometimes, the file Rewards_Siebel misses records from file Rewards_Header.

So, Please let me know what is the commend to check if all three files are merged into file Rewards_Siebel

Apart from the fact that you should use "CODE"-tags, as stated in the forum rules and even in the creation mask for any new thread, this won't work at all.

You can't read from a file ("cat Rewards_Siebel") and write to it ("> Rewards_Siebel") at the same time, for reasons stated here. You will have to create a temporary file and the move it over the original file "Rewards_Siebel" to get what you want.

I hope this helps.

bakunin

Hi bakunin,

Thanks for your reply,
It is not like reading from a file ("cat Rewards_Siebel") and write to it ("> Rewards_Siebel") at the same time.

We have three different files 'Rewards_Header', 'Rewards_Siebel_Notif_temp' and 'Rewards_Siebel_Remind105_temp' trying to write to file 'Rewards_Siebel'.

I just wanted to know the possible way of checkng if the merging of these three files into one file 'Rewards_Siebel' is successful or not.

How about computing MD5 sum and comparing:

MD5_INV=$( cat Rewards_Header Rewards_Siebel_Notif_temp Rewards_Siebel_Remind105_temp | md5sum | awk '{ print $1 }' )
MD5_MRG=$( md5sum Rewards_Siebel | awk '{ print $1 }' )

[[ "$MD5_INV" == "$MD5_MRG" ]] && echo "Success"

OK, my bad. Sorry. I must have misread the filenames somehow.

This can't fail in normal circumstances, because this is what "cat" is for: ConCATenate files. As long as i.e. the disk is not full "cat" is supposed to work.

You might have special characters in (one of) your files: file-end-markers or similar. Use "od -ax <file> | more" to check for that. As a more simple test open it in "vi" and enter ":set list" to display normally unprintable characters.

I would point you to the exit code (=error level) of "cat", but this would reflect only errors in the operation of "cat" itself: a full disk or other unability to write the output file would show there, but malformed ASCII-files do not affect "cat"s operation and therefore will not reflect there.

I hope this helps.

bakunin

If cat fails, cat will tell you so. You can plug it directly into if.

if ! cat file1 file2 file3
then
        echo "merge failed"
fi