Basic question on comparing two text files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Basic question on comparing two text files
# 1  
Old 11-21-2012
Basic question on comparing two text files

RHEL 5.4 (Korn shell)

I have two files
First file
Code:
$ cat myfile_1.txt
JOHN
KEITH
CHANG
JUDE
CHRISTINE
KRISHNA
AHMED
ULRICH
JESSICA

-- Second file has 3 names missing (AHMED, ULRICH, JESSICA )
Code:
$ cat myfile_2.txt
JOHN
KEITH
CHANG
JUDE
CHRISTINE
KRISHNA

I want to compare these two files and find what are the missing values in myfile_2.txt. How can I do that ?
# 2  
Old 11-21-2012
comm is specifically designed for this task. You could also accomplish this with grep, using the correct options.

Regards,
Alister
# 3  
Old 11-21-2012
Code:
diff myfile1.txt myfile2.txt

# 4  
Old 11-21-2012
Code:
awk 'FNR==NR{f[$0]; next;} { if(!($1 in f)) print;} ' myfile_2.txt myfile_1.txt
AHMED
ULRICH
JESSICA

# 5  
Old 11-21-2012
Hi

Code:
$ comm -23 <(sort myfile_1.txt) <(sort myfile_2.txt)
AHMED
JESSICA
ULRICH

Guru.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing columns in 2 text files

Hi i have 2 files file1.txt XX,ZZ,XC,EE,RR,BB XC,CF,FG,RG,GH,GH File2.txt DF,GH,MH,FR,FG,GH,NOTOK XX,ZZ,XC,EE,RR,BB,OK result XX,ZZ,XC,EE,RR,BB OK look for column1 , XX and if it matches in File2.txt , retrieve the 7 th field from File2 and print in 3 rd file , ... (9 Replies)
Discussion started by: Shyam_84
9 Replies

2. Shell Programming and Scripting

Need Help in comparing 2 text files in shell script

Hi All, I have 2 files like below vi f1 frog elephant rabit zebra dog vi f2 rabit dog ============== Now i want to comapre two files and the result will be frog (8 Replies)
Discussion started by: kumar85shiv
8 Replies

3. UNIX for Dummies Questions & Answers

Comparing and merging two text files

Hey everybody, I am new here and already a question to ask, I just recently started some bioinformatic work for my PhD so I am slowly learning Anyway, here is my problem, I have two text files, one contains the complete data file with 43000 genes and their read counts for all my samples... (1 Reply)
Discussion started by: ant55
1 Replies

4. Shell Programming and Scripting

Comparing 2 huge text files

I have this 2 files: k5login sanwar@systems.nyfix.com jjamnik@systems.nyfix.com nisha@SYSTEMS.NYFIX.COM rdpena@SYSTEMS.NYFIX.COM service/backups-ora@SYSTEMS.NYFIX.COM ivanr@SYSTEMS.NYFIX.COM nasapova@SYSTEMS.NYFIX.COM tpulay@SYSTEMS.NYFIX.COM rsueno@SYSTEMS.NYFIX.COM... (11 Replies)
Discussion started by: linuxgeek
11 Replies

5. Shell Programming and Scripting

comparing to text files

Hi All, I have two files of the following formats file 1 - this is a big file >AB_1 gi|229194403|ref|ZP_04321208.1| group II intron reverse transcriptase/maturase gdfjafhlkhlnlklaklskckcfhhahgfahajfkkallalfafafa >AB_2 gi|229194404|ref|ZP_04321209.1| gfksjgfkjsfjslfslfslhf >AB_3... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

6. Shell Programming and Scripting

comparing 2 text files to get unique values??

Hi all, I have got a problem while comparing 2 text files and the result should contains the unique values(Non repeatable). For eg: file1.txt 1 2 3 4 file2.txt 2 3 So after comaping the above 2 files I should get only 1 and 4 as the output. Pls help me out. (7 Replies)
Discussion started by: smarty86
7 Replies

7. AIX

comparing within text files

hi! some looping problem here... i have a 2-column text file 4835021 20060903FAL0132006 4835021 20060904FAL0132006 4835021 20060905FAL0132006 4835023 20060903FAL0132006 4835023 20061001HAL0132006 4835023 ... (3 Replies)
Discussion started by: d3ck_tm
3 Replies

8. UNIX for Dummies Questions & Answers

Ignoring Some Text When Comparing 2 Files

Hi Guys, How can I compare 2 text files and show the differences between the 2 files but have some of the text ignored? Example File1 File2 Thomas Thomass !1st name! David Davidd !2nd name! John John !3rd name! So,... (1 Reply)
Discussion started by: jimmyflip
1 Replies

9. UNIX for Dummies Questions & Answers

comparing text files

I am comparing text files where there are number of rows of numbers from window to unix box Is there any way of checking lets say 4 document of text file and seeing the difference only (or missing rows of numbers) with simple commands with lets say a batch file FROM ABSOULTE... (2 Replies)
Discussion started by: sjumma
2 Replies
Login or Register to Ask a Question