I'm on macOS Mojave and trying to use regex to output the results of a match in 2 different columns
I have a file that contains these strings:
JJ1111-Aaaaaa-AB-22222222-f_2-777777_S1_L000_trtrt JJ1111-Baaaaa-AB-22322222-f_2-777777_S1_L000_trtrt JJ1111-Caaaaa-AB-22222322-f_2-777777_S1_L000_trtrt I want to extract the "Aaaaaa" (or the string of 6 consecutive charaters) and the String of 2 capital letters "AB".
Now the command
egrep -oh '[a-zA-Z]{6}' my.txt will return
Aaaaaa Baaaaa Caaaaa And
egrep -oh '\-[A-Z]{2}' my.txt | sed 's/-//g' will return
AB AB AB Is there a way (I'm thinking using awk), to output the two matches in a new file with 2 columns that are separated with tabs? I've tried this:
awk '{$1 ~ /[a-zA-Z]{6}/; print $1}' my.txt But only gives me the original string of characters
-a separatorawk -F'-' '$2 ~ /[a-zA-Z]{6}/ && $3 ~ /[A-Z]{2}/ {print $2"\t"$3}'