Compare list [ names and size files ]

Hello,

I've downloaded a huge amont of files

I've got a list of files from a remote server.

-rw-r--r-- 1 str661 strem 453465260 Dec 16 15:54 SATRYS2V1_20021218_temp_bias.nc
-rw-r--r-- 1 str661 strem  17669468 Dec 16 18:01 SATRYS2V1_20021225_hdyn_bias.nc
-rw-r--r-- 1 str661 strem 453465248 Dec 16 18:01 SATRYS2V1_20021225_sali_bias.nc
-rw-r--r-- 1 str661 strem 453465260 Dec 16 18:01 SATRYS2V1_20021225_temp_bias.nc

I've got also the same list

-rw-r--r--   1 mar_stl marsstr  453465260 Dec 16 15:54 SATRYS2V1_20021218_temp_bias.nc
-rw-r--r--   1 mar_stl marsstr  17669468 Dec 16 18:01 SATRYS2V1_20021225_hdyn_bias.nc
-rw-r--r--   1 mar_stl marsstr  453465248 Dec 16 18:01 SATRYS2V1_20021225_sali_bias.nc
-rw-r--r--   1 mar_stl marsstr  453465260 Dec 16 18:01 SATRYS2V1_20021225_temp_bias.nc

I need help to found a way to compare name files and size and see if there is any difference. The idea is to be sure the size of each file are exacly the same.

Thanks for your help

Try

while read j1 j2 j3 j4 size j5 j6 j7 file
do
  if [ -s "$file" ] && [ "$(wc -c < "$file")" -eq "$size" ];
  then
    echo $file: ok
  else
    echo $file: nok
  fi
done < file
1 Like

If i understood correctly..

awk 'NR==FNR{a[$NF]=$5;next}(a[$NF]!=$5){print "Difference: " $NF}' localfile remotefile > outfile
1 Like

Dear anchal_khare,

I do not anderstand your code. Do you mind explain it to me as I do not know where I should enter the remote liste and the local list ?
thanks

---------- Post updated at 04:44 AM ---------- Previous update was at 04:40 AM ----------

Dear michaelrozar17,

your line code is correct and seems fine ... but, do thinks it will be possible to add that

: if the file is correct print the file name ? ... like this

Correct :  SATRYS2V1_20021218_temp_bias.nc

on this way it will be more esay for me to make a report ..

so far here what I am getting :

Difference: SATRYS2V1_20030101_hdyn_bias.nc

Thanks

If your requirement matches with michaelrozar17, then my solution wont work. so please ignore.

BTW, I assumed that you have the remote file list in a file. and the files you want to compare are present locally.

I see that you have mentioned "list" for both which I didn't see.

Dear anchal_khare,

I made a file list from the remote sever and another file list with what I have on local.

I 've moved of list on my temporary directory to compare both of the list.

I believed your script compare a list file made on the remote server and compare with what I have on the directory. If is this way how works the code, I will try anyway. I want to say thansk a lot for your help, and in other way make your work as help to anyone that will try to do the same thnigs I am doing.

Just change not-equal-to to equal-to operator.

awk 'NR==FNR{a[$NF]=$5;next}(a[$NF]==$5){print "Correct: " $NF}' localfile remotefile > outfile

Dear michaelrozar17

awk 'NR==FNR{a[$NF]=$5;next}(a[$NF]==$5){print "Correct: " $NF}' localfile remotefile > outfile

Here is the output result :

Correct: 1041212078
Correct: 850566644

I did try to do the same things which 2 identical list and I've got the same result ? Is there something I lost in the way ?

Do you think it will be possible to get all files name instead of the size ?

Thanks

---------- Post updated at 05:27 AM ---------- Previous update was at 05:24 AM ----------

I also try to compare difference of 2 identical list and the output code says that each file is different ??

Here the line code used :

awk 'NR==FNR{a[$NF]=$5;next}(a[$NF]==$5){print "Correct: " $NF}' localfile remotefile > outfile

I am lost please help

You should get only file names instead of size.$NF represents last column in your file. So if your file contains the last column as file name then it should print as Correct: filename.txt. And you have confirmed the same in the updated post#4 Difference: GLORYS2V1_20030101_hdyn_bias.nc. Moreover be clear which file your going to compare with which.
The given code compares the local file with the remote file list and output's remote list's file which are matching.

Dear michaelrozar17,

As all members are working sometimes hard for me, here is my feedback :

I found why your code given as not working as expected. I am on solaris an if I use awk instaed of nwak, the result is not the same.

So here is the solution for me : I use NWAK

Note the highlighted code:

nawk 'NR==FNR{a[$NF]=$5;next}(a[$NF]==$5){print "Correct: " $NF}' localfile remotefile > outfile

Result is working fine.

I am also testing the script code given by anchal_khare.

It's working fine and seems to be also able to handle different organisation in the list. I mean if the result of

ls -l 

on the remote server returns different output from the local server.

Thanks