Found and Notfound compare two file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Found and Notfound compare two file
# 1  
Old 02-06-2018
Found and Notfound compare two file

File1

Code:
site1.111.com
site1.333.com
site1.555.uk

file2

Code:
site1.222.test
site1.111.com
site1.333.com
site1.444.test
site1.555.uk

Need Result

Code:
site1.222.test,Notfound
site1.111.com,found
site1.333.com,found
site1.444.com,Notfound
site1.555.uk,found

I was trying to do using for loop but i cant update the notfound comment

Last edited by ranjancom2000; 02-06-2018 at 01:44 PM..
# 2  
Old 02-06-2018
Can you post your for loop code? We can help you fix your code.
# 3  
Old 02-06-2018
Hello ranjancom2000,

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

Output will be as follows.
Code:
222,Notfound
111,found
333,found
444,Notfound
555,found

Thanks,
R. Singh
# 4  
Old 02-06-2018
Hi Ravin,

It was printing for all lines notfound
# 5  
Old 02-06-2018
My first question would be, is the input for "file1" and "file2" representative of your actual input? e.g. Ravinder's solution is working on the entire line of input. If the data you've shown is only part of the line, it won't work if the rest of the line does not match in both files.

Also, as Yoda suggests, post your for-loop code. Perhaps we could help you understand why that isn't working.
# 6  
Old 02-06-2018
Also, try Ravinder's suggestion again but this time with $1 instead of $0 for all occurrences.
# 7  
Old 02-06-2018
Hi Scott,

I have update the file in thread one it will be similar to 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