In the awk
below I am trying to add adjust $2
in the ouput by adding +1
if the original value from file that was used in $2
had a -
in it. Line 2 of in
is an example of this. In my current awk
I my logic is not correct as I am looking in $2
and splitting on the -
and storing the values in 'array' if there is one and keeping the count of the fields in num
. Based on the count in num
I print the output of the split or no split. In my actual data there may be hundreds of lines but always the same format. Seems close but not quite there. Thank you :).
in
chr15 91543131 AAW33B
chr8 100493900-100493909 SBSA
awk
awk '{num=split($2,array,"[ -]");if(num==3){print $1,$2-1,$2,$3};if(num==4){print $1,array[1],array[2],array[2],$3}}' in | column -t
desired tab-delimited
chr15 91543130 91543131 AAW33B
chr8 100493900 100493909 SBSA
---
or just-
? Is the--- num==3??? ---
part of your input?FS
to/[ -]/
and then look atNF
to determine what your output should be.