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 -
. In my actual data there may be hundreds of lines but always the same format. Thank you :).
file
2019 NGS-A Gene and Chromosomal Position List,,,,
Gene Symbol,HGNC ID,Transcript Number,Chromosomal Position/Interval ,Required (Exome and Genome Labs)
VPS13B,HGNC:2183,NM_017890.4,chr8 100493900-100493909,yes
VPS33B,HGNC:12712,NM_018668.4,chr15 91543131,
current
chr8 100493899 100493909 VPS13B
chr15 91543130 91543131 VPS33B
desired
chr8 100493900 100493909 VPS13B
chr15 91543130 91543131 VPS33B
awk
awk -F, 'FNR > 2 {for(i=1;i<=NF;i++){if($i~/^chr/){a=$i}} print a,$1}' file | awk -F'[ :-]' 'NF==3{$4=$3;$3=$2} {$1=$1} 1' OFS='\t' | awk -F'\t' '{print $1,$2-1,$3,$4}' OFS="\t" out