在AWK中转义反斜杠 [英] Escaping backslash in AWK
本文介绍了在AWK中转义反斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图理解为什么下面的命令不起作用(输出为空):
I'm trying to understand why the command below doesn't work (output is empty):
echo 'aaa\tbbb' | awk -F '\\t' '{print $2}'
我希望输出为'bbb'.
I would expect the output to be 'bbb'.
有趣的是,此方法有效(输出为"bbb"):
Interestingly this works (output is 'bbb'):
echo 'aaa\tbbb' | awk -F 't' '{print $2}'
这也有效(输出是'tbbb'):
And this works as well (ouptut is 'tbbb'):
echo 'aaa\tbbb' | awk -F '\\' '{print $2}'
看起来\\\t
读为反斜杠,后跟制表符,而不是转义的反斜杠,后跟t .
是否有编写此命令的正确方法?
Is there a proper way to write this command?
推荐答案
您需要告诉echo
解释反斜杠转义符.试试:
You need to tell echo
to interpret backslash escapes. Try:
$ echo -e 'aaa\tbbb' | awk -F '\t' '{print $2}'
bbb
man echo
会告诉:
-e enable interpretation of backslash escapes
这篇关于在AWK中转义反斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文