任何等同于
echo "(one) ... (two)" |awk -F "\.\.\." '{print $2}' # works in linux
适用于mac os
echo "(one) ... (two)" |awk -F " ... " '{print $2}' # 'works' when we add spaces
或使用单点分隔符
echo "(one) ... (two)" |awk -F "\." '{print $4}'
但是有多个点(或带有单个空格的点)失败(给出不同的解释)?
尝试echo "(one) ... (two)" |awk -F " \." '{print $2}'
或echo "(one) ... (two)" |awk -F "\. " '{print $2}'
答案 0 :(得分:2)
当你在字段分隔符中使用正则表达式时,使用一个反斜杠转义特殊字符并不意味着什么特别的东西。你必须这样做:
$ echo "(one) ... (two)" | awk -F "\\\.\\\.\\\." '{for(i=1;i<=NF;i++) print "$"i " is "$i}' | cat -ve
$1 is (one) $
$2 is (two)$
更好的方法是将特殊字符放在字符类中以将其视为字面值。
$ echo "(one) ... (two)" | awk -F "[.]{3}" '{for(i=1;i<=NF;i++) print "$"i " is "$i}' | cat -ve
$1 is (one) $
$2 is (two)$