bash 如何在 awk 中调用 split 函数以在“\.”上拆分字符串?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9874921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I call the split function in awk to split a string on "\."?
提问by user1268200
How do I use the split
function to split by "\."?
如何使用split
函数以“\.”分割?
For example, first consider splitting by :
:
例如,首先考虑拆分为:
:
echo "03:26:12" | awk '{split(122603
,a,":"); print a[3] a[2] a[1]}'
Which produces this output:
产生这个输出:
echo "03\.26\.12" | awk '{split(122603
,a,???); print a[3] a[2] a[1]}'
But if the incoming string is instead:
但是如果传入的字符串是:
echo "03\.26\.12" | awk '{split(122603
,a,/\\./); print a[3] a[2] a[1]}'
With desired output:
具有所需的输出:
echo "03\.26\.12" | awk '{split(##代码##,a,"\\."); print a[3] a[2] a[1]}'
What should the ???
be?
应该???
是什么?
采纳答案by Birei
You must escape both characters:
您必须转义这两个字符:
##代码##Result:
结果:
##代码##回答by Umae
This gives the same output.
这给出了相同的输出。