Unix parsing pipe delimited format string in ksh

妖精的绣舞 提交于 2019-12-02 01:45:32

The shell can do it:

line="123|456|789"
IFS='|' read a b c <<END
$line
END
echo $c  # => 789

You can't assign awk variables (i.e. output[3]) to shell variables (i.e. dummy), you can only assign the output of awk to a variable, e.g.

export dummy=`echo "123|456|789" | awk -F'|' '{ print $3; }'`

However, awk is a bit overkill here, cut will work just as well:

export dummy=`echo "123|456|789" | cut -d'|' -f3`
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!