Comparing two txt files with AWK


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Comparing two txt files with AWK
# 1  
Old 05-16-2012
Comparing two txt files with AWK

Hi,

I need to compare two text files with awk.

File1:
-------
Code:
chr1    43815007        43815009        COSM19193       REF=TG;OBS=AA;ANCHOR=G  AMPL495041
chr1    43815008        43815009        COSM18918       REF=G;OBS=T;ANCHOR=T    AMPL495041
chr1    115256527       115256528       COSM585 REF=T;OBS=A;ANCHOR=C    AMPL30014

File2:
--------
Code:
##FORMAT=<ID=AST,Number=.,Type=Integer,Description="Allelic unique start positions for the REF and ALT alleles in the order listed in the ALT field">
##FORMAT=<ID=ABQV,Number=.,Type=Integer,Description="Allelic average base qv for the REF and ALT alleles in the order listed  in the ALT field">
#CHROM  POS     ID      REF     ALT     QUAL    FILTER  INFO    FORMAT  Sample
chr1    15860185        .       C       T       100     PASS    .       GT:GQ:GL:DP:FDP:AD:APSD:AST:ABQV        1/1:100.00:-999.00,-999.00,0.00:18:17:0,17:0,0:0,4:0,23
chr1    18116310        .       A       T       27      PASS    .       GT:GQ:GL:DP:FDP:AD:APSD:AST:ABQV        1/1:24.08:-2.71,-2.71,-0.00:3:3:0,3:0,3:0,1:0,25
chr1    24470994        .       T       C       27      PASS    .       GT:GQ:GL:DP:FDP:AD:APSD:AST:ABQV        1/1:24.08:-2.71,-2.71,-0.00:4:3:0,3:0,3:0,1:0,21

I want to compare these two files such that we can check the entry in File 2 to falls in the range specified in File1 or not.

Need to get the position from File1 (column 2 and column 3 e.g. for line no.1 43815007, 43815008, 43815009) for value in column 1 i.e. chr1. Now want to check the column 1 and column 2 in File2 and check the value for column 2 is in the range specified in File1.


I am very new to AWK and not sure about comparing two files in awk.

Any help in this would be of greatest help. Smilie

Thanks,
RushiK

Last edited by radoulov; 05-16-2012 at 06:21 AM..
# 2  
Old 05-17-2012
Define check: - report the good ones or report the bad ones, or what?
# 3  
Old 05-18-2012
Ohh many apologies for that!!

We just need to print the messsage:

e.g."
Case1: If no entry in file2 is out of the range specified in file 1

Message: passed successfully

else

Failed
# 4  
Old 05-18-2012
I noticed column1 has the same value all the time, is that also the case with the real file?
# 5  
Old 05-23-2012
No, column1 can have multiple values (ex: chr1, chr2, chr3 etc)

Thanks,
Rushi
# 6  
Old 05-23-2012
Yes, but in either file, can there be multiple lines that have chr1 in field 1?
# 7  
Old 05-23-2012
Yes, there can be multiple lines in either files.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing two .txt files

i am working on a shell script and need help in the comparing part of it. for e.g. there two text files like this: file1.txt Code: name1 name2 name3 file1 has to be comared with file2 defaultfile.txt Code: name1 name2 (16 Replies)
Discussion started by: draghun9
16 Replies

2. Shell Programming and Scripting

Reading txt files using the awk

Dear Shell scripters, I have a small code which copy the txt files from some destination to file name OutPutFile. I want to modify this script to introduce several constant. The string it is reading is like ... (2 Replies)
Discussion started by: nrjrasaxena
2 Replies

3. Shell Programming and Scripting

Comparing the matches in two files using awk when both files have their own field separators

I've two files with data like below: file1.txt: AAA,Apples,123 BBB,Bananas,124 CCC,Carrot,125 file2.txt: Store1|AAA|123|11 Store2|BBB|124|23 Store3|CCC|125|57 Store4|DDD|126|38 So,the field separator in file1.txt is a comma and in file2.txt,it is | Now,the output should be... (2 Replies)
Discussion started by: asyed
2 Replies

4. Shell Programming and Scripting

comparing 2 files with awk

Hi, I'm a new user in awk and i'm trying to compare two files to create a third one if some values match in both files. The first file has this content: s 45.960746365 _21_ AGT 2490 [21:0 22:0 s 45.980418496 _21_ AGT 2491 [21:0 22:0 s 46.000090627 _21_ AGT 2492 [21:0 22:0 s 47.906552206... (2 Replies)
Discussion started by: carlosoria
2 Replies

5. Shell Programming and Scripting

Comparing Strings in 2 .csv/txt files?

EDIT: My problems have been solved thanks to the help of bartus11 and pravin27 This code is just to help me learn. It serves no purpose other than that. Here's a sample csv that I'm working with - #listofpeeps.csv Jackie Chan,1954,M Chuck Norris,1930,M Bruce Lee,1940,M This code is... (13 Replies)
Discussion started by: chickeneaterguy
13 Replies

6. Shell Programming and Scripting

comparing two files using awk

hit brick wall while trying to knock up a script that will take values from the "lookup" file and look it up in the "target" file and return values that dont appear in "target" but do in "lookup". just knocked up something using bits from previous threads but theres gotta be something wrong... (13 Replies)
Discussion started by: jack.bauer
13 Replies

7. Shell Programming and Scripting

awk-files in a txt

There is a file that contains access's data to a web server. Each line of the file (it's big) it's : IP Client - - "Command Path Protocol" code size "client software" Example,for the first line: IP Client is 67.195.37.107, date-hour is , Command Path Protocol is "Get /papers/ISO4nm.pdf ... (1 Reply)
Discussion started by: Mark_orig
1 Replies

8. Shell Programming and Scripting

Comparing two files using awk

Hi, I have 2 text files n1 and n2. cat n1 : -------- 1234567890 4444444444 cat n2 : --------- 1234567890 4444444444 7777777777 8888888888 they are some sample records. File n1 contains some lookup records, whereas file n2 contains some transaction records. I need to get the... (2 Replies)
Discussion started by: kanu_kanu
2 Replies

9. Shell Programming and Scripting

Comparing two .txt files in shell scripting...

Hi, I have two big .txt files.and i need to compare those two files and redirect it into some other file. If any body wants to resolve this issue then i can send the two text files. Need some quick responce. Thanks, prakash (10 Replies)
Discussion started by: prakash123
10 Replies

10. Shell Programming and Scripting

Comparing two txt files - pls help

Hi, I have some text files. I need a separate shell say 1.sh in which i can open a particular text file and compare with another txt file. For example: 1.log.txt contains apple ball cat goat 2.log.txt contains goat cat lion apple fox In my i.sh i need to write script to... (5 Replies)
Discussion started by: jisha
5 Replies
Login or Register to Ask a Question