Compare two column in file and extract complate line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Compare two column in file and extract complate line
# 1  
Old 05-03-2013
Compare two column in file and extract complate line

Code:
No Chr   Pos              Qual     GT_1   GT_2
1. chr1   478493       595     A/G     G/G
2. chr1    879243     700       A/T      T/T
3. chr2    889922     1300    C/C     C/C
4. chr2    1926372    300     T/A     T/A 
5. chr3     237474     500      G/C       C/C
6. chr3      575757    700      A/T       T/T
7. chr3    6666874    746       T/T       T/T

I have one file with six column file is tab delimited. I like to check if column GT_1 and GT_2 did not match, print complete line and at the end It also count how many A/G converted to G/G , AT converted to T/T . It has to skip all lines in which GT_1 column has same value in GT_2 for example both column has T/T and t/A value in line 7 and 4 respectively. I don't know We can compare text value like T/A in unix or not because I don't have numeric values in my problem. Thanks for your time for my question

Last edited by radoulov; 05-03-2013 at 12:53 PM..
# 2  
Old 05-03-2013
A start...

Code:
$ cat sample32.txt
No Chr   Pos              Qual     GT_1   GT_2
1. chr1   478493       595     A/G     G/G
2. chr1    879243     700       A/T      T/T
3. chr2    889922     1300    C/C     C/C
4. chr2    1926372    300     T/A     T/A
5. chr3     237474     500      G/C       C/C
6. chr3      575757    700      A/T       T/T
7. chr3    6666874    746       T/T       T/T

$ awk '{if ($5!=$6) {print $0}}' <sample32.txt
No Chr   Pos              Qual     GT_1   GT_2
1. chr1   478493       595     A/G     G/G
2. chr1    879243     700       A/T      T/T
5. chr3     237474     500      G/C       C/C
6. chr3      575757    700      A/T       T/T

# 3  
Old 05-03-2013
I think the complete answer now...

Code:
$ awk '($5!=$6) {print $0}; ($5=="A/G")&&($6=="G/G") {++cnt1} ; ($5=="A/T")&&($6=="T/T") {++cnt2} ; END { print "Counts="cnt1" & "cnt2 }' <sample32.txt
No Chr   Pos              Qual     GT_1   GT_2
1. chr1   478493       595     A/G     G/G
2. chr1    879243     700       A/T      T/T
5. chr3     237474     500      G/C       C/C
6. chr3      575757    700      A/T       T/T
Counts=1 & 2

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare 1st column from 2 file and if match print line from 1st file and append column 7 from 2nd

hi I have 2 file with more than 10 columns for both 1st file apple,0,0,0...... orange,1,2,3..... mango,2,4,5..... 2nd file apple,2,3,4,5,6,7... orange,2,3,4,5,6,8... watermerlon,2,3,4,5,6,abc... mango,5,6,7,4,6,def.... (1 Reply)
Discussion started by: tententen
1 Replies

2. UNIX for Dummies Questions & Answers

Extract columns based on the first line of each column

Sorry to bother you guys again. I have a file1 with multiple columns like this:gga_miR_100 gga_miR_300 gga_miR_3500 gga_miR_4600 gga_miR_5600 gga_miR_30 gga_miR_500 kj rwg ghhh jy jyu we vf 5g 5hg h6 56h i8 45t 44r4 4bg 4r546 9lgtr (fer) 4fr f433 3feev f4 bf4 35g vfr ge 2rr ... (5 Replies)
Discussion started by: yuejian
5 Replies

3. Shell Programming and Scripting

Compare the second column of a file with the second column of another in awk

Hi, I know that this topic has been discussed in the past and I've tried to follow all the guidelines. Anyhow, I following describe my problem. I have a file (file1 , no. records = 67) containing pairs of IP addresses as follows (with single space as delimiter between the fields): example... (5 Replies)
Discussion started by: amarn
5 Replies

4. Shell Programming and Scripting

Compare files & extract column awk

I have two tab delimited files as given below: File_1: PV16 E1 865 2814 1950 PV16 E2 2756 3853 1098 PV16 E4 3333 3620 288 PV16 E5 3850 4101 252 PV16 E6 83 559 477 PV16 E7 562 858 297 PV16 L2 4237 5658 ... (10 Replies)
Discussion started by: vaibhavvsk
10 Replies

5. Shell Programming and Scripting

Extract Line and Column from CSV Line in ksh or bash format

Hi, I was doing some research and can't seem to find anything. I'm trying to automate a process by creating a script to read a csv line and column and assigning that value to a variable for the script to process it. Also if you could tell me the line and column if it's on another work ... (3 Replies)
Discussion started by: vpundit
3 Replies

6. Shell Programming and Scripting

compare files and remove a line from a file if first column is greater than 25

my files are as follows fileA sepearated by tab /t 00 lieferungen 00 attractiop 01 done 02 forness 03 rasp 04 alwaysisng 04 funny 05 done1 fileB funnymou120112 funnymou234470 mou3raspnhdhv rddfgmoudone1438748 so all those record which are greater than 3 and which are not... (4 Replies)
Discussion started by: rajniman
4 Replies

7. Shell Programming and Scripting

Extract first column from second line in perl

Hello Gurus I have a source file which has the first line as header and the rest are the records I need to extract the first column from the second line to extract a value I/P ... (7 Replies)
Discussion started by: Pratik4891
7 Replies

8. Shell Programming and Scripting

How to extract 3rd line 4th column of a file

Hi, Shell script: I would need help on How to extract 3rd line 4th column of a file with single liner Thanks in advance. (4 Replies)
Discussion started by: krishnamurthig
4 Replies

9. Shell Programming and Scripting

compare the column from 3 files and merge that line

I have 3 file, each of has got 80000 records. file1.txt ----------------------- ABC001;active;modify;accept; ABC002;notactive;modify;accept; ABC003;notactive;no-modify;accept; ABC004;active;modify;accept; ABC005;active;no-modify;accept; file2.txt ---------------------------... (8 Replies)
Discussion started by: ganesh_mak
8 Replies

10. Shell Programming and Scripting

I need to extract last column of a file and compare the values

Hi, I am new to unix and I need help in solving below mentioned issue, really appreciate ur help. I have a file sam, john, 2324, 07142007 tom, thomson, 2343, 07142007 john, scott, 2478, 07142007 its a comma delimited file, I need to extract the last column from each line and this... (4 Replies)
Discussion started by: vukkusila
4 Replies
Login or Register to Ask a Question