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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check if the merge of two files is successful?
# 1  
Old 01-09-2013
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,

Code:
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

Moderator's Comments:
Mod Comment edit by bakunin: Please view this code tag video for how to use code tags when posting code and data.

Last edited by bakunin; 01-09-2013 at 10:54 AM..
# 2  
Old 01-09-2013
Quote:
Originally Posted by anandek
Code:
cat Rewards_Header Rewards_Siebel_Notif_temp Rewards_Siebel_Remind105_temp > 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
# 3  
Old 01-10-2013
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.
# 4  
Old 01-10-2013
How about computing MD5 sum and comparing:
Code:
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"

# 5  
Old 01-10-2013
Quote:
Originally Posted by anandek
We have three different files 'Rewards_Header', 'Rewards_Siebel_Notif_temp' and 'Rewards_Siebel_Remind105_temp' trying to write to file 'Rewards_Siebel'.
OK, my bad. Sorry. I must have misread the filenames somehow.

Quote:
Originally Posted by anandek
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.
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
# 6  
Old 01-10-2013
If cat fails, cat will tell you so. You can plug it directly into if.

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check email successful sent and receive

We have a unix/linux server , that send mass email from it , the emails will pass the smtp gateway , email server and sent to the client , but sometimes the client do not receive the mail , we do not know the reason and when it will happen . We would like to have a script that check when the... (2 Replies)
Discussion started by: ust4
2 Replies

2. Shell Programming and Scripting

How to check the status of sftp connection is successful or not in Linux?

Hi All, We are working on linux with putty terminal for file transferring using SFTP server... here we want to know /We have Urgent Requirement If SFTP connection is successfull then we should get .txt log file in target locaton as "Success/Failure" Please provide batch script for above... (7 Replies)
Discussion started by: sravanreddy
7 Replies

3. UNIX for Dummies Questions & Answers

Ftp - file transfer and check successful delivery

In shell script, I want to transfer files continuously and make sure transfer is successful. Please advise... how to make sure ftp transfer is successful? Also is there any option such as sftp -b where I can pass multiple put <file name> commands to ftp Thanks! (1 Reply)
Discussion started by: vegasluxor
1 Replies

4. Shell Programming and Scripting

How to check whether the sftp script is successful??

hi, how can i check whether the sftp connectivity is successful or not?? i am using expect script to connect to sftp.. sftp_script spawn /usr/bin/sftp abc@ftp.xyz.com expect "abc@ftp.xyz.com's password:" send "password\r" expect "sftp>" send "mput *.txt\r" expect "sftp>" send "bye\r"... (8 Replies)
Discussion started by: Little
8 Replies

5. Shell Programming and Scripting

FTP Status check(whether it is successful or not)

Hi Friends I need to check the status of FTP connection i.e. Whether it is successful or not I have tried this by assigning the FTP connection script to a variable and after that using this variable I tried to check the status. In the below code snippet I am trying to assign the FTP... (1 Reply)
Discussion started by: Kannannair
1 Replies

6. Shell Programming and Scripting

Checking in a directory how many files are present and basing on that merge all the files

Hi, My requirement is,there is a directory location like: :camp/current/ In this location there can be different flat files that are generated in a single day with same header and the data will be different, differentiated by timestamp, so i need to verify how many files are generated... (10 Replies)
Discussion started by: srikanth_sagi
10 Replies

7. Homework & Coursework Questions

Script to check transfer was successful

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a script that performs a post processing action: The run time environment of the script has the... (2 Replies)
Discussion started by: kenrowe
2 Replies

8. Shell Programming and Scripting

rm files after testing for successful scp

First off, I know this is sort of a rehash of similar questions that have been asked in other closed threads, but I haven't been able to figure out how to apply the answers provided in those threads to my scenario and make it work. I am working on a script in KSH on AIX 5.1 that will do a bulk... (1 Reply)
Discussion started by: derndingle
1 Replies

9. Shell Programming and Scripting

For loop scp transfers check if all iterations successful

All, I am using a for loop to SCP a bunch of files in a directory. I am having it then drop a .ready file name. Is there a way to check for the success of all iterations and then email upon fail or success? Example of part of my script: for file in $ORIGLOC/* do ] &&... (2 Replies)
Discussion started by: markdjones82
2 Replies

10. Shell Programming and Scripting

Merge files of differrent size with one field common in both files using awk

hi, i am facing a problem in merging two files using awk, the problem is as stated below, file1: A|B|C|D|E|F|G|H|I|1 M|N|O|P|Q|R|S|T|U|2 AA|BB|CC|DD|EE|FF|GG|HH|II|1 .... .... .... file2 : 1|Mn|op|qr (2 Replies)
Discussion started by: shashi1982
2 Replies
Login or Register to Ask a Question