awk do not split if condition is meet


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers awk do not split if condition is meet
# 1  
Old 06-13-2019
awk do not split if condition is meet

Trying to use awk to format the input based on the filed count being 5. Most lines are fine using the awk below, except the first two lines. I know the reason is the -1 in green and -2 in blue. But can not figure out how to not split on the - if it is followed by a digit then letter. Thank you Smilie.

input

Code:
chr9:21971208 CDKN2A c.151-1G>A p.?
chr9:21971209 CDKN2A c.151-2A>G p.?
chr5:112175216 APC c.3925G>T p.E1309*
chr5:112175363 APC c.4072G>A p.A1358T
chr5:112175390 APC c.4099C>T p.Q1367*
EGFR,,EGFR c.2240_2257delTAAGAGAAGCAACATCTC p.L747_P753delinsS,chr7:55242470_55242487delTAAGAGAAGCAACATCTC,3470,,,,

current

Code:
chr9 21971208 CDKN2A c.151 1G>A p.?
chr9 21971209 CDKN2A c.151 2A>G p.?
chr5 112175216 112175216 APC p.E1309*
chr5 112175363 112175363 APC p.A1358T
chr5 112175390 112175390 APC p.Q1367*
chr7 55242470 55242487 EGFR c.2240_2257delTAAGAGAAGCAACATCTC p.L747_P753delinsS

desired

Code:
chr9 21971208 21971208 CDKN2A c.151-1G>A p.?
chr9 21971209 21971209 CDKN2A c.151-2A>G p.?
chr5 112175216 112175216 APC p.E1309*
chr5 112175363 112175363 APC p.A1358T
chr5 112175390 112175390 APC p.Q1367*
chr7 55242470 55242487 EGFR c.2240_2257delTAAGAGAAGCAACATCTC p.L747_P753delinsS

awk

Code:
awk -F'[ :_-]' 'NF==5{$4=$3;$3=$2} {$1=$1} 1' input


Last edited by cmccabe; 06-13-2019 at 07:24 PM..
# 2  
Old 06-14-2019
I am very confused.

The last line of your sample input contains at least 7 fields so the {$1=$1}1 should change colons, underscores, and minus signs to spaces leaving the rest of that line of input unchanged. But, instead of that, you say that you want something that replaces field 1 with the contents of the last four characters from field number 5 and rearranges lots of other parts of that input line???

Since the only minus signs in your sample input are characters that you do not want to count as field separators, why are you including them in your list of field separator characters???

Why is it that the first five lines of your output desired output don't all have the same number of fields??? If they all start out with what you want to count as five fields, shouldn't they all end up with the same number of output fields?

Please try again to explain what it is that you are trying to do and provide sample input and output that match the description of what you are trying to do!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print lines that meet conditions and have value in another file

I am trying to use awk to print lines that satisfy either of the two conditions below: condition 1: $2 equals CNV and the split of $3, the value in red, is greater than or equal to 4. ---- this is a or so I think condition 2: $2 equals CNV and the split of $3, the value in red --- this is a... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Print header and lines that meet both conditions in awk

In the awk below I am trying to print only the header lines starting with # or ## and the lines that $7 is PASS and AF= is less than 5%. The awk does execute but returns an empty file and I am not sure what I am doing wrong. Thank you. file ... (0 Replies)
Discussion started by: cmccabe
0 Replies

3. Shell Programming and Scripting

awk to capture lines that meet either condition

I am trying to modify and understand an awk written by @Scrutinizer The below awk will filter a list of 30,000 lines in the tab-delimited file. What I am having trouble with is adding a condition to SVTYPE=CNV that will only print that line if CI=,0.95: portion in blue in file is <1.9. The... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. Shell Programming and Scripting

awk to print matching lines in files that meet critera

In the tab delimited files below I am trying to match $2 in file1 to $2 of file2. If a match is found the awk checks $3 of file2 and if it is greater than 40% and $4 of file2 is greater than 49, the line in file1 is printed. In the desired output line3 of file1 is not printed because $3 off file2... (9 Replies)
Discussion started by: cmccabe
9 Replies

5. Shell Programming and Scripting

How to Split File to 2 depending on condition?

Hi , cat myfile.txt ! 3100.2.0.5 ! 3100.2.22.4 ! 3100.2.30.33 ! 3100.2.4.1 ! ! 3100.2.0.5 ! 3100.2.22.4 ! 3100.2.22.11 ! 3100.2.4.1 ! ! 3100.2.0.5 ! 3100.2.2.50 ! 3100.2.22.11 ! 3100.2.4.1 ! ! 3100.2.0.5 ! 3100.2.22.4 ! 3100.2.30.33 ! 3100.2.4.1 ! ! 3100.2.0.5 ! 3100.2.22.4 !... (6 Replies)
Discussion started by: OTNA
6 Replies

6. Shell Programming and Scripting

how to use split command in unix shell with a condition

Hi all, I have a file which I want to split into several files based on a condition. This files has several records. I want one record per file. Each record ends with a //. So, I want to separate files based on this condition. I want split files to be named with the name across the field ID (for... (2 Replies)
Discussion started by: kaav06
2 Replies

7. Shell Programming and Scripting

Printing records which meet condition using awk

Below is the code nawk -F"|" 'tolower($1) ~ "abc" |"" {if (tolower($2) ~"abc"|"") print$0}' file I want the records from file whose 1st and 2nd field should be either "abc" or "null" I tried but its giving error. Appreciate help (2 Replies)
Discussion started by: pinnacle
2 Replies

8. Shell Programming and Scripting

split file with condition

$ cat file H1:12:90 k:12:b n:22:i k:54:b k:42:b s:48:s a:41:b t:18:n c:77:a I am trying to split above file based on $2 such that if $2 is rounded to nearest 10's multiple (e.g. 10,20,30 etc), each sub file should contain 3 multiples and so on (also I want to keep header i.e. NR==1, in... (6 Replies)
Discussion started by: uwork72
6 Replies

9. Shell Programming and Scripting

How to split the String based on condition?

hi , I have a String str="/opt/ibm/lotus/ibw/latest" or ="/opt/lotus/ibw/latest" this value is dynamic..I want to split this string into 2 strings 1. /opt/ibm/lotus(/opt/lotus) this string must ends with "lotus" 2./ibw/latest can any body help me on this? Regards, sankar (2 Replies)
Discussion started by: sankar reddy
2 Replies

10. Shell Programming and Scripting

awk script to split a file based on the condition

I have the file with the records like 4234234 US phone 3244234 US cup 2342342 CA phone 8947234 US phone 2389472 CA cup 2348972 US maps 3894234 CA phone I want the records with (US,phone) as record to be in one file, (Us, cup) in another file and (CA,cup) to be in another I mean all... (12 Replies)
Discussion started by: superprogrammer
12 Replies
Login or Register to Ask a Question