Printing out lines that have the same value in the first column but different value in the second


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Printing out lines that have the same value in the first column but different value in the second
# 1  
Old 02-12-2013
Printing out lines that have the same value in the first column but different value in the second

Hi,

I have a text file that looks like the following:

Code:
ILMN_1343291    6       74341083        74341772
ILMN_1343291    6       74341195        74341099
ILMN_1343295    12      6387581 6387650
ILMN_1651209    1       1657001 1657050
ILMN_1651209    5      83524260        83524309

I would like to print out all the lines where the values in the first column match but the values in the second column do not match, so the resulting output would look like the following:

Code:
ILMN_1651209    1       1657001 1657050
ILMN_1651209    5      83524260        83524309

Thanks!
# 2  
Old 02-12-2013
Code:
awk 'f==$1&&s!=$2{print c;print}{f=$1;s=$2;c=$0}' file

This User Gave Thanks to Yoda For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read first column and count lines in second column using awk

Hello all, I would like to ask your help here: I've a huge file that has 2 columns. A part of it is: sorted.txt: kss23 rml.67lkj kss23 zhh.6gf kss23 nhd.09.fdd kss23 hp.767.88.89 fl67 nmdsfs.56.df.67 fl67 kk.fgf.98.56.n fl67 bgdgdfg.hjj.879.d fl66 kl..hfh.76.ghg fl66... (5 Replies)
Discussion started by: Padavan
5 Replies

2. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

3. Shell Programming and Scripting

Inconsistent column printing

Hi, I have a file that has inconsistently numbered columns. Like row1 has 23 columns, and row 2 has 34 columns etc. I would like to re-order the first 8 columns as required and from the 9th column till the end, I would like to print it as it is. I tried to read the re-ordered 8 columns... (7 Replies)
Discussion started by: jacobs.smith
7 Replies

4. Shell Programming and Scripting

Find lines with matching column 1 value, retain only the one with highest value in column 2

I have a file like: I would like to find lines lines with duplicate values in column 1, and retain only one based on two conditions: 1) keep line with highest value in column 3, 2) if column 3 values are equal, retain the line with the highest value in column 4. Desired output: I was able to... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

5. Shell Programming and Scripting

printing certain elelment of a column

"File1.txt" CHR SNP BP ANNOT 8 rs1878374 127974042 MYC(-843.5kb)|FAM84B(+334.4kb) 2 rs2042077 16883103 VSNL1(-702.2kb)|SMC6(-825.5kb)|RAD51AP2(-672.4kb)|MYCN(+878.5kb)|MSGN1(-978.2kb)|GEN1(-915.6kb)|FAM49A(+172.5kb) 12 rs10431347 3023955... (4 Replies)
Discussion started by: johnkim0806
4 Replies

6. Shell Programming and Scripting

Column printing in awk

Experts, i have a following file containing data in following manner. 1 2480434.4 885618.6 0.00 1948.00 40.00 1952.00 ... (6 Replies)
Discussion started by: Amit.saini333
6 Replies

7. Shell Programming and Scripting

Printing the lines that appear in an other file, and the three lines after them

Hi ! I need some help with a script I am writing. I am trying to compare two files, the first file being in this format : Header1 Text1-1 Text1-2 Text1-3 Header2 Text2-1 etc... For each header, I want to check if it appears in the second file, and if it is the case print the header... (4 Replies)
Discussion started by: jbi
4 Replies

8. Shell Programming and Scripting

Filtering lines for column elements based on corresponding counts in another column

Hi, I have a file like this ACC 2 2 21 aaa AC 443 3 22 aaa GCT 76 1 33 xxx TCG 34 2 33 aaa ACGT 33 1 22 ggg TTC 99 3 44 wee CCA 33 2 33 ggg AAC 1 3 55 ddd TTG 10 1 22 ddd TTGC 98 3 22 ddd GCT 23 1 21 sds GTC 23 4 32 sds ACGT 32 2 33 vvv CGT 11 2 33 eee CCC 87 2 44... (1 Reply)
Discussion started by: polsum
1 Replies

9. Shell Programming and Scripting

Printing all lines before a specific string and a custom message 2 lines after

Hello all, I need to print all the lines before a specific string and print a custom message 2 lines after that. So far I have managed to print everything up the string, inclusively, but I can't figure out how to print the 2 lines after that and the custom message. My code thus far is:... (4 Replies)
Discussion started by: SEinT
4 Replies

10. UNIX for Dummies Questions & Answers

creating a file using the fist column and printing second column

Hello all. I have a problem that I need help solving. I would like to convert the following file: human pool1_12 10e-02 45 67 human pool1_1899 10e-01 45 29 human pool1_1829 10e-01 43 26 horse pool1_343 10e-20 65 191 horse pool1_454 10e-09 44 43... (5 Replies)
Discussion started by: viralnerd
5 Replies
Login or Register to Ask a Question