Found and Notfound compare two file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Found and Notfound compare two file
# 8  
Old 02-06-2018
Quote:
Originally Posted by ranjancom2000
Hi Scott,
I have update the file in thread one it will be similar to that
Hello ranjancom2000,

My same code is working for your newly shown Input_file(s), please do let us know what is not working(with complete details). Simply saying not working will not help us to help you and try to show us all Input_file sample in a single post itself.
Code:
awk 'FNR==NR{a[$0];next} {printf("%s\n",$0 in a?$0",found":$0",Notfound")}' FiLE1  FiLE2
site1.222.test,Notfound
site1.111.com,found
site1.333.com,found
site1.444.test,Notfound
site1.555.uk,found

EDIT: In case your Input_file(s) have carriage returns in them which you could check by doing cat -v Input_file, if they have it and run following code:
Code:
awk 'FNR==NR{gsub(/\r/,"");a[$0];next} {gsub(/\r/,"");printf("%s\n",$0 in a?$0",found":$0",Notfound")}' FiLE1  FiLE2

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 9  
Old 02-06-2018
One reason any solution for the files in post#1 will fail is that file1 has DOS line terminators (<CR> <LF>), while file2 has *nix ones (just <LF>).

Last edited by RudiC; 02-06-2018 at 01:57 PM..
# 10  
Old 02-06-2018
thanks it was working has some space
# 11  
Old 05-08-2018
Sorry please ignore this. I have update on another post which is more related to it

I need to check the column 3 from file1 and compare it with Colume1 of file 1 and append.

File1
Code:
533 Server1 002D9 34526
533 Server1 002DA 34526
533 Server1 002DB 34526
533 Server1 002DC 34526
533 Server1 002DD 34526
533 Server1 002DE 34526
533 Server1 002DF 34526
533 Server1 002E1 34526
533 Server1 002E2 34526
533 Server1 002E3 34526
533 Server1 002E4 34526
533 Server1 002E5 34526
533 Server1 002E6 34526
533 Server1 002E7 34526

File2
Code:
002D9 RDFType:R1 RemoteDeviceSymmetrixName:001DD RemoteSymmetrixID:000296700555
002DA RDFType:R1 RemoteDeviceSymmetrixName:001DE RemoteSymmetrixID:000296700555
002DB RDFType:R1 RemoteDeviceSymmetrixName:001DF RemoteSymmetrixID:000296700555
002DC RDFType:R1 RemoteDeviceSymmetrixName:001E0 RemoteSymmetrixID:000296700555
002DD RDFType:R1 RemoteDeviceSymmetrixName:001E1 RemoteSymmetrixID:000296700555
002DE RDFType:R1 RemoteDeviceSymmetrixName:001E2 RemoteSymmetrixID:000296700555
002DF RDFType:R1 RemoteDeviceSymmetrixName:001E3 RemoteSymmetrixID:000296700555
002E0 RDFType:R1 RemoteDeviceSymmetrixName:001E4 RemoteSymmetrixID:000296700555
002E1 RDFType:R1 RemoteDeviceSymmetrixName:001E5 RemoteSymmetrixID:000296700555
002E2 RDFType:R1 RemoteDeviceSymmetrixName:001E6 RemoteSymmetrixID:000296700555
002E3 RDFType:R1 RemoteDeviceSymmetrixName:001E7 RemoteSymmetrixID:000296700555
002E4 RDFType:R1 RemoteDeviceSymmetrixName:001E8 RemoteSymmetrixID:000296700555
002E5 RDFType:R1 RemoteDeviceSymmetrixName:001E9 RemoteSymmetrixID:000296700555
002E6 RDFType:R1 RemoteDeviceSymmetrixName:001EA RemoteSymmetrixID:000296700555
002E7 RDFType:R1 RemoteDeviceSymmetrixName:001EB RemoteSymmetrixID:000296700555

Output required

Code:
533 Server1 002D9 34526 002D9 RDFType:R1 RemoteDeviceSymmetrixName:001DD RemoteSymmetrixID:000296700555
533 Server1 002DA 34526 002DA RDFType:R1 RemoteDeviceSymmetrixName:001DE RemoteSymmetrixID:000296700555
533 Server1 002DB 34526 002DB RDFType:R1 RemoteDeviceSymmetrixName:001DF RemoteSymmetrixID:000296700555
533 Server1 002DC 34526 002DC RDFType:R1 RemoteDeviceSymmetrixName:001E0 RemoteSymmetrixID:000296700555
533 Server1 002DD 34526 002DD RDFType:R1 RemoteDeviceSymmetrixName:001E1 RemoteSymmetrixID:000296700555
533 Server1 002DE 34526 002DE RDFType:R1 RemoteDeviceSymmetrixName:001E2 RemoteSymmetrixID:000296700555
533 Server1 002DF 34526 002DF RDFType:R1 RemoteDeviceSymmetrixName:001E3 RemoteSymmetrixID:000296700555
Notfound 002E0 RDFType:R1 RemoteDeviceSymmetrixName:001E4 RemoteSymmetrixID:000296700555
533 Server1 002E1 34526 002E1 RDFType:R1 RemoteDeviceSymmetrixName:001E5 RemoteSymmetrixID:000296700555
533 Server1 002E2 34526 002E2 RDFType:R1 RemoteDeviceSymmetrixName:001E6 RemoteSymmetrixID:000296700555
533 Server1 002E3 34526 002E3 RDFType:R1 RemoteDeviceSymmetrixName:001E7 RemoteSymmetrixID:000296700555
533 Server1 002E4 34526 002E4 RDFType:R1 RemoteDeviceSymmetrixName:001E8 RemoteSymmetrixID:000296700555
533 Server1 002E5 34526 002E5 RDFType:R1 RemoteDeviceSymmetrixName:001E9 RemoteSymmetrixID:000296700555
533 Server1 002E6 34526 002E6 RDFType:R1 RemoteDeviceSymmetrixName:001EA RemoteSymmetrixID:000296700555
533 Server1 002E7 34526 002E7 RDFType:R1 RemoteDeviceSymmetrixName:001EB RemoteSymmetrixID:000296700555


Last edited by ranjancom2000; 05-08-2018 at 02:29 PM..
# 12  
Old 05-08-2018
Hello ranjancom2000,

Could you please try following and let me know if this helps you.
Code:
awk 'FNR==NR{a[$3]=$0;next} {printf("%s %s\n",$1 in a?a[$1]:"Notfound",$0)}'  Input_file1   Input_file2

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 13  
Old 05-08-2018
Quote:
Originally Posted by RavinderSingh13
Hello ranjancom2000,

Could you please try following and let me know if this helps you.
Code:
awk 'FNR==NR{a[$3]=$0;next} {printf("%s %s\n",$1 in a?a[$1]:"Notfound",$0)}'  Input_file1   Input_file2

Thanks,
R. Singh

I can able to resolve this from this post since sorry for that.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

While loop a file containing list of file names until the files are found?

Hi, I have a control file which will contain all filenames(300) files. Loop through all the file names in the control files and check the existence of this file in another directory(same server). I need to infinitely(2 hrs) run this while loop until all the files are found. Once a file is found,... (5 Replies)
Discussion started by: laknar
5 Replies

3. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

4. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

5. UNIX for Dummies Questions & Answers

look for specific values in a file and rename file with value found

Hi, i have a file with some data ..look for some specific value in the file and if found that value rename the file with the value found in the file.. ex.. File.txt 1236 43715825601ANDERSSON, 1236 437158256031963040120060901200609010000000 1236 43715825604123 MCCL AVE UPPER 1236 ... (11 Replies)
Discussion started by: dssyadav
11 Replies

6. Shell Programming and Scripting

Modify a file by another file: add new line and variable after string is found

hello, I have problem with writing/adjusting a shell script. I searched forum and unfortunately couldn't write scipt based on the information I found. I never wtire such so it's hard for me and I do need to modify one script immediately. case looks like: 1. 'file' that needs to be modified... (3 Replies)
Discussion started by: bipbip
3 Replies

7. Shell Programming and Scripting

Search for file, give error if more than one file is found

Want to write a function that prints an error when passed a list of file names. If the file list is empty, print error "no file found", if there are more than one file, print "error more than one file found" (22 Replies)
Discussion started by: kristinu
22 Replies

8. Shell Programming and Scripting

Delete a pattern present in file 2 from file 1 if found in file 1.

I have two files File1 ==== 1|2000-00-00|2010-02-02|| 2| 00:00:00|2012-02-24|| 3|2000-00-00|2011-02-02|| File2 ==== 2000-00-00 00:00:00 I want the delete the patterns which are found in file 2 from file 1, Expected output: File1 ==== (5 Replies)
Discussion started by: machomaddy
5 Replies

9. UNIX for Dummies Questions & Answers

12. If an ‘88’ Record with BAI Code ‘902’ was found on input file and not written to Output file, re

This is my input file like this 03,105581,,015,+00000416418,,,901,+00000000148,,,922,+00000000354,,/ 49,+00000000000416920,00002/ 03,5313236,,015,+00231036992,,,045,+00231036992,,,901,+00000048428,,/ 88,100,+0000000000000,0000000,,400,+0000000000000,0000000,/ 88,902,+0000000079077,,/... (0 Replies)
Discussion started by: sgoud
0 Replies

10. Shell Programming and Scripting

how can i check in csh if command found or not found ?

hello all im trying to use in sun Solaris the information received from the top command now i several machines that dont have install the top program so when im running the script im geting error saying after im running this code : set MemoryInfo = `top | grep Memory` if (... (2 Replies)
Discussion started by: umen
2 Replies
Login or Register to Ask a Question