如何仅打印最后一列?

兰斯·贝恩斯
echo -e 'one two three\nfour five six\nseven eight nine'
one two three
four five six
seven eight nine

我该如何做一些“魔术”来获得此输出?:

three
six
nine

更新:我不需要这种特定的方式,我需要一个通用的解决方案,以便无论一行中有多少列,例如:awk始终显示最后一列。

jfg956

它甚至可以只完成'bash',无'sed''awk''perl'

echo -e 'one two three\nfour five six\nseven eight nine' |
  while IFS=" " read -r -a line; do
    nb=${#line[@]}
    echo ${line[$((nb - 1))]}
  done

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章