Remove lines based on column value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove lines based on column value
# 1  
Old 12-19-2011
Remove lines based on column value

Hi All,
I just need a quick fix here. I need to delete all lines containing "." in the 6th column.

Input:
Code:
1       1055498 .       G       T       5.46    .       
1       1902377 .       C       T       7.80    .       
1       1031540 .       A       G       34.01   PASS    
1       1032841 .       G       T       14.92   LowQual

Desired Output:
Code:
1       1031540 .       A       G       34.01   PASS    
1       1032841 .       G       T       14.92   LowQual

---------- Post updated at 07:30 PM ---------- Previous update was at 07:29 PM ----------

I would also like to know how to replace the "." with "-1" if possible

Last edited by zxmaus; 12-19-2011 at 09:45 PM..
# 2  
Old 12-19-2011
Quote:
Originally Posted by Hkins552
Hi All,
I just need a quick fix here. I need to delete all lines containing "." in the 6th column.

Input:
1 1055498 . G T 5.46 .
1 1902377 . C T 7.80 .
1 1031540 . A G 34.01 PASS
1 1032841 . G T 14.92 LowQual

Desired Output:
1 1031540 . A G 34.01 PASS
1 1032841 . G T 14.92 LowQual
Code:
awk '$7 == "." { next } { print }' "$file"

Quote:

---------- Post updated at 07:30 PM
---------- Previous update was at 07:29 PM ----------


I would also like to know how to replace the "." with "-1" if possible
Code:
awk '$7 == "." { $7 = "-1" } { print }' "$file"

These 2 Users Gave Thanks to cfajohnson For This Post:
# 3  
Old 12-20-2011
Quote:
Originally Posted by Hkins552
I would also like to know how to replace the "." with "-1" if possible
In case you're referring to the "." in the 3rd field:

Code:
awk '$7 == "." {next}; $3 == "." {$3 = "-1"} {print}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove duplicate rows based on one column

Dear members, I need to filter a file based on the 8th column (that is id), and does not mather the other columns, because I want just one id (1 line of each id) and remove the duplicates lines based on this id (8th column), and does not matter wich duplicate will be removed. example of my file... (3 Replies)
Discussion started by: clarissab
3 Replies

2. Shell Programming and Scripting

How to remove a line based on contents of the first column?

Good day all. Using basic UNIX/Linux tools, how would you delete a line based on a character found in column 1? For example, if the CITY name contains an 'a' or 'A', delete the line: New York City; New York Los Angeles; California Chicago; Illinois Houston; Texas Philadelphia;... (3 Replies)
Discussion started by: BRH
3 Replies

3. Shell Programming and Scripting

Two files, remove lines from second based on lines in first

I have two files, a keepout.txt and a database.csv. They're unsorted, but could be sorted. keepout: user1 buser3 anuser19 notheruser27 database: user1,2343,"information about",field,blah,34 user2,4231,"mo info",etc,stuff,43 notheruser27,4344,"hiya",thing,more thing,423... (4 Replies)
Discussion started by: esoffron
4 Replies

4. Shell Programming and Scripting

remove column based on the same value

Hello, I have some problem to remove the columns which have the duplicate value of -9 which is in every row except -9 in some row. Input file showed in below : Col1 Col2 Col3 Col4 Col5 Col6 A 1 A -9 0 -9 B 2 T -9 -9 -9 C 3 D -9 1 -9 D 4 R -9 2 -9 Output should... (6 Replies)
Discussion started by: awil
6 Replies

5. 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

6. UNIX for Dummies Questions & Answers

Remove duplicate rows when >10 based on single column value

Hello, I'm trying to delete duplicates when there are more than 10 duplicates, based on the value of the first column. e.g. a 1 a 2 a 3 b 1 c 1 gives b 1 c 1 but requires 11 duplicates before it deletes. Thanks for the help Video tutorial on how to use code tags in The UNIX... (11 Replies)
Discussion started by: informaticist
11 Replies

7. Shell Programming and Scripting

remove duplicates based on single column

Hello, I am new to shell scripting. I have a huge file with multiple columns for example: I have 5 columns below. HWUSI-EAS000_29:1:105 + chr5 76654650 AATTGGAA HHHHG HWUSI-EAS000_29:1:106 + chr5 76654650 AATTGGAA B@HYL HWUSI-EAS000_29:1:108 + ... (4 Replies)
Discussion started by: Diya123
4 Replies

8. Shell Programming and Scripting

need to remove duplicates based on key in first column and pattern in last column

Given a file such as this I need to remove the duplicates. 00060011 PAUL BOWSTEIN ad_waq3_921_20100826_010517.txt 00060011 PAUL BOWSTEIN ad_waq3_921_20100827_010528.txt 0624-01 RUT CORPORATION ad_sade3_10_20100827_010528.txt 0624-01 RUT CORPORATION ... (13 Replies)
Discussion started by: script_op2a
13 Replies

9. UNIX for Dummies Questions & Answers

Remove duplicates based on a column in fixed width file

Hi, How to output the duplicate record to another file. We say the record is duplicate based on a column whose position is from 2 and its length is 11 characters. The file is a fixed width file. ex of Record: DTYU12333567opert tjhi kkklTRG9012 The data in bold is the key on which... (1 Reply)
Discussion started by: Qwerty123
1 Replies

10. UNIX for Dummies Questions & Answers

Remove duplicate rows of a file based on a value of a column

Hi, I am processing a file and would like to delete duplicate records as indicated by one of its column. e.g. COL1 COL2 COL3 A 1234 1234 B 3k32 2322 C Xk32 TTT A NEW XX22 B 3k32 ... (7 Replies)
Discussion started by: risk_sly
7 Replies
Login or Register to Ask a Question