bash 替换 cut --output-delimiter
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20195728/
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
replacement for cut --output-delimiter
提问by Marcos
I created a script that was using
我创建了一个正在使用的脚本
cut -d',' -f- --output-delimiter=$'\n'
to add a newline for each command separated value in RHEL 5, for e.g.
在 RHEL 5 中为每个命令分隔值添加一个换行符,例如
[root]# var="hi,hello how,are you,doing"
[root]# echo $var
hi,hello how,are you,doing
[root]# echo $var|cut -d',' -f- --output-delimiter=$'\n'
hi
hello how
are you
doing
But unfortunately when I run the same command in Solaris 10, it doesn't work at all :( !
但不幸的是,当我在 Solaris 10 中运行相同的命令时,它根本不起作用:(!
bash-3.00# var="hi,hello how,are you,doing"
bash-3.00# echo $var
hi,hello how,are you,doing
bash-3.00# echo $var|cut -d',' -f- --output-delimiter=$'\n'
cut: illegal option -- output-delimiter=
usage: cut -b list [-n] [filename ...]
cut -c list [filename ...]
cut -f list [-d delim] [-s] [filename]
I checked the man page for 'cut' and alas there is no ' --output-delimiter ' in there !
我检查了'cut'的手册页,可惜那里没有'--output-delimiter'!
So how do I achieve this in Solaris 10 (bash)? I guess awk would be a solution, but I'm unable to frame up the options properly.
那么我如何在 Solaris 10 (bash) 中实现这一点?我想 awk 将是一个解决方案,但我无法正确构建选项。
Note: The comma separated variables might have " " space in them.
注意:逗号分隔的变量中可能有 " " 空格。