更换切--output分隔符 [英] replacement for cut --output-delimiter

查看:244
本文介绍了更换切--output分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了使用脚本

cut -d',' -f- --output-delimiter=$'\n'

添加一个新行每个命令分隔值在RHEL 5,对于例如。

to add a newline for each command separated value in RHEL 5, for e.g.

[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

但不幸的是,当我运行Solaris 10中相同的命令,它不会在所有的工作:(!

But unfortunately when I run the same command in Solaris 10, it doesn't work at all :( !

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]

我检查了手册页'一刀切'唉没有--output分隔符在那里!

I checked the man page for 'cut' and alas there is no ' --output-delimiter ' in there !

那么,如何在我的Solaris 10(bash)的实现这一目标?我想AWK将是一个解决方案,但我无法正确地架起的选项。

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.

注:逗号分隔的变量可能有,空间在其中

Note: The comma separated variables might have " " space in them.

推荐答案

有关使用什么 TR 此?

$ tr ',' '\n' <<< "$var"
hi
hello how
are you
doing

$ echo $var | tr ',' '\n'
hi
hello how
are you
doing

使用 SED

$ sed 's/,/\n/g' <<< "$var"
hi
hello how
are you
doing

或用 AWK

$ awk '1' RS=, <<< "$var"
hi
hello how
are you
doing

这篇关于更换切--output分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆