It is a trick; setting the last field forces a reformatting with the OFS. (The previous fields are empty.) The order matters, OFS must be set first. Therefore I think the following is cleaner
awk 'BEGIN{OFS="-\t"; $12="-"; print}' </dev/null
Perl has the x operator
perl -e '{print "-\t"x11, "-\n"}'
In bash and zsh:
{ for i in {1..11}; do printf -- "-\t"; done; printf -- "-\n"; }
No. You can say that a string argument in an awk print statement is a string; not a regular expression. If you want an ERE to select lines containing exactly 11 copies of "-\t" followed by a final "-" and only print those lines, you could try:
Thanks Don and all!
What I was doing is to combined two files (each half million lines) by a matching column, if no match (0.01%), make up the missing fields with the "-" , which triggered me asking if there is regex for my purpose:
Typing that long string "-\t" repetitively looks dull, and I felt dizzy counting the number of tabs while typing. I made mistakes and need re-run a couple of times to get it correct! So I thought if there is regex I could avoid the mistake.
Thanks again!
I'm a little confused since the code you showed us is printing tabs between the hyphens in the output, but the sample output you provided from that command has four spaces at those spots instead of a singe tab. And, the output you showed us should have output lines in the order of the lines in file1, but it doesn't. It also seems strange that there are three trailing spaces on each line in your sample file2 , but there are zero, two, or three spaces on the corresponding lines in your sample output. I don't know if that matters for the output you hope to produce, but it makes it hard to guess at what you are really trying to do???
So, with lots of unsupported guesswork, the following (combining earlier suggestions with your code to merge files and making the wild assumption that if you want tabs between hyphens, you might also want tab to be your output field separator) might or might not come close to producing the output you want:
You seem to be caught in an error: regexes exist for searching/matching purposes ONLY. You can't print them. For printing a repetitive pattern, you need to type it as is, use a loop, or fall back to tricks as posted before.