Reputation: 925
Any equivalent to
echo "(one) ... (two)" |awk -F "\.\.\." '{print $2}' # works in linux
which works on mac os
echo "(one) ... (two)" |awk -F " ... " '{print $2}' # 'works' when we add spaces
or use single dot separator
echo "(one) ... (two)" |awk -F "\." '{print $4}'
but with more than one dot (or dot with single space) fails (gives different interpretations)?
try echo "(one) ... (two)" |awk -F " \." '{print $2}'
or echo "(one) ... (two)" |awk -F "\. " '{print $2}'
Upvotes: 0
Views: 362
Reputation: 77155
When you use a regex in field separator, escaping the special character with one back slash doesn't really mean anything special. You'll have to do:
$ echo "(one) ... (two)" | awk -F "\\\.\\\.\\\." '{for(i=1;i<=NF;i++) print "$"i " is "$i}' | cat -ve
$1 is (one) $
$2 is (two)$
The better way to do is put the special character in a character class to consider it literal.
$ echo "(one) ... (two)" | awk -F "[.]{3}" '{for(i=1;i<=NF;i++) print "$"i " is "$i}' | cat -ve
$1 is (one) $
$2 is (two)$
Upvotes: 3