In GNU Awk's 4.1.2 Record Splitting with gawk we can read:
When
RSis a single character,RTcontains the same single character. However, whenRSis a regular expression,RTcontains the actual input text that matched the regular expression.
This variable RT is very useful in some cases.
Similarly, we can set a regular expression as the field separator. For example, in here we allow it to be either ";" or "|":
$ gawk -F';' '{print NF}' <<< "hello;how|are you"
2 # there are 2 fields, since ";" appears once
$ gawk -F'[;|]' '{print NF}' <<< "hello;how|are you"
3 # there are 3 fields, since ";" appears once and "|" also once
However, if we want to pack the data again, we don't have a way to know which separator appeared between two fields. So if in the previous example I want to loop through the fields and print them together again by using FS, it prints the whole expression in every case:
$ gawk -F'[;|]' '{for (i=1;i<=NF;i++) printf ("%s%s", $i, FS)}' <<< "hello;how|are you"
hello[;|]how[;|]are you[;|] # a literal "[;|]" shows in the place of FS
Is there a way to "repack" the fields using the specific field separator used to split each one of them, similarly to what RT would allow to do?
(the examples given in the question are rather simple, but just to show the point)