Remove line based on condition in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove line based on condition in awk
# 8  
Old 08-26-2016
Note that some alphabetic characters are interpreted as parts of numeric values when awk converts a string to a number. The standards require that exponential notation be recognized (e.g., 1.05E-3) and allows but does not require awk to recognize hexadecimal constants of the forms 0xhexdigits and 0Xhexdigits. And, the standards allow, but do not currently require that the strings inf and infinity (case-insensitive on both) be treated as an infinity and that the string NaN (also case-insensitive) be treated as not-a-number.
This User Gave Thanks to Don Cragun For This Post:
# 9  
Old 08-26-2016
@RavinderSingh13 here is the result of the awk. Thank you all for your help Smilie.

Code:
awk -F'\t' '($7 ~ /intronic||UTR3||UTR5/){v=$2;a=sub(/^[^+-]+\+/,X,v);if(a){sub(/([><]).*/,X,v)};if((v+0)>10){next}} 1'  Input_file

output
Code:
Index    Mutation Call    Start    End    Ref    Alt    Func.refGene    Gene.refGene    ExonicFunc.refGene    Sanger
3    c.276-31delG    43396570    43396570    C    -    intronic    SLC2A1        
4    c.[13-22T>C]+[13-22T>C]    160090674    160090674    T    C    intronic    ATP1A2        
5    c.13-11_13-8delTCCT    160090685    160090688    TCCT    -    intronic    ATP1A2        
12    c.[268-28A>G]+[268-28A>G]    166153499    166153499    A    G    intronic    SCN2A        
13    c.[1035-3T>C]+[1035-3T>C]    166170127    166170127    T    C    intronic    SCN2A        
15    c.[1672-16C>T]+[1672-16C>T]    166179650    166179650    C    T    intronic    SCN2A        
16    c.[2994C>T]+[=]    166210776    166210776    C    T    exonic    SCN2A    synonymous SNV    
17    c.[3400-71C>T]+[3400-71C>T]    166221582    166221582    C    T    intronic    SCN2A        
18    c.4552-40delT    166243216    166243216    T    -    intronic    SCN2A        
19    c.[4914T>A]+[4914T>A]    166245230    166245230    T    A    exonic    SCN2A    synonymous SNV    
20    c.[5109C>T]+[=]    166245425    166245425    C    T    exonic    SCN2A    synonymous SNV    
21    c.[5139C>T]+[=]    166848646    166848646    G    A    exonic    SCN1A    synonymous SNV    
22    c.3152_3153insAACCACT    166892841    166892841    -    AGTGGTT    exonic    SCN1A    frameshift insertion    TP
23    c.2044-5delT    166898947    166898947    A    -    intronic    SCN1A        
24    c.[1663-47T>G]+[1663-47T>G]    166900606    166900606    A    C    intronic    SCN1A        
25    c.1530_1531insA    166901684    166901684    -    T    exonic    SCN1A    frameshift insertion    FP
26    c.[-44C>T]+[=]    66094008    66094008    C    T    UTR5    KCTD7
27    c.[*68A>G]+[=]    125880589    125880589    T    C    UTR3    ALDH7A1

@Chubler_XL

The awk is missing the last line (Index 27) presumably because of the *. Would adding \*\ capture that condition? Thank you Smilie.

Adding to the range was what I needed to do sub(/^[^*+-]+[*+-]/,"",v)

Last edited by cmccabe; 08-26-2016 at 10:53 AM.. Reason: added details, updated awk
# 10  
Old 08-26-2016
Try also
Code:
awk '$7 ~/intronic|UTR(3|5)/{match ($2, /[+-][0-9]*/); if (10 < 0+substr($2, RSTART+1, RLENGTH-1)) next}1' file

These 2 Users Gave Thanks to RudiC For This Post:
# 11  
Old 08-26-2016
works great @RudiC... thank you Smilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk to add +1 to value based on condition in input

In the awk below I am trying to add a | that will adjust $2 in the ouput by adding +1 if the original value from file that was used in $3 had a - in it. Line 3 of file is an example of this. In my current awk I just subtract one but I am not sure how to only apply this to those values without a -.... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Shell Programming and Scripting

awk to reformat lines based on condition

The awk below uses the tab-delimeted fileand reformats each line based on one of three conditions (rules). The 3 rules are for deletion (lines in blue), snv (line in red), and insertion (lines in green). I have included all possible combinations of lines from my actual data, which is very large.... (0 Replies)
Discussion started by: cmccabe
0 Replies

3. Shell Programming and Scripting

Help with awk color codes based on condition

HI i have two files say test and test1 Test.txt Code: Lun01 2TB 1.99TB 99.6% Lun02 2TB 1.99TB 99.5% Lun03 2TB 1.99TB 99.5% Lun04 2TB 1.55TB 89.6% Code: Test1.txt Lun01 2TB 1.99TB 89.5% Lun02 2TB 1.99TB 99.5% Lun03 2TB 1.99TB 99.5% Requirement is to compare... (6 Replies)
Discussion started by: venkitesh
6 Replies

4. Shell Programming and Scripting

Print lines based on line number and specified condition

Hi, I have a file like below. 1,2,3,4,5,6,7,8,9I would like to print or copied to a file based of line count in perl If I gave a condition 1 to 3 then it should iterate over above file and print 1 to 3 and then again 1 to 3 etc. output should be 1,2,3 4,5,6 7,8,9 (10 Replies)
Discussion started by: Anjan1
10 Replies

5. Shell Programming and Scripting

Multi line extraction based on condition

Hi I have some data in a file as below ****************************** Class 1A Students absent are : 1. ABC 2. CDE 3. CPE ****************************** Class 2A Students absent are : ****************************** Class 3A Students absent are : (6 Replies)
Discussion started by: reldb
6 Replies

6. Shell Programming and Scripting

Remove duplicate line on condition

Hi Ive been scratching over this for some time with no solution. I have a file like this 1 bla bla 1 2 bla bla 2 4 bla bla 3 5 bla bla 1 6 bla bla 1 I want to remove consecutive occurrences of lines like bla bla 1, but the first column may be different. Any ideasss?? (23 Replies)
Discussion started by: jamie_123
23 Replies

7. Shell Programming and Scripting

ksh: how to extract strings from each line based on a condition

Hi , I'm a newbie.Never worked on Unix before. I want a shell script to perform the following: I want to extract strings from each line ,based on the type of line(Nameline,Subline) and output it to another file.Below is a sample format. 2010-12-21 14:00"1"Nameline"Midterm"First Name:Jane ... (4 Replies)
Discussion started by: angie1234
4 Replies

8. Shell Programming and Scripting

Remove lines from XML based on condition

Hi, I need to remove some lines from an XML file is the value within a tag is empty. Imagine this scenario, <acd><acdID>2</acdID><logon></logon></acd> <acd><acdID></acdID><logon></logon></acd> <acd><acdID></acdID><logon></logon></acd> <acd><acdID></acdID><logon></logon></acd> I... (3 Replies)
Discussion started by: giles.cardew
3 Replies

9. Shell Programming and Scripting

awk to print lines based on string match on another line and condition

Hi folks, I have a text file that I need to parse, and I cant figure it out. The source is a report breaking down softwares from various companies with some basic info about them (see source snippet below). Ultimately what I want is an excel sheet with only Adobe and Microsoft software name and... (5 Replies)
Discussion started by: rowie718
5 Replies

10. Shell Programming and Scripting

How to search then remove based on condition

Folks; I'm trying to write a script to scan through a directory tree then for each file it finds, it run a command line tool, then if the results include the word "DONE", it removes the file. In more details; i have a Linux directory tree such as "/opt/grid/1022/store" I'm trying to write a... (6 Replies)
Discussion started by: Katkota
6 Replies
Login or Register to Ask a Question