awk相当于MySQL的substring_index

时间:2012-08-21 15:57:15

标签: awk

我有带分隔字段的字符串,但每个字段中包含不同数量的字段,例如:

  • this / that
  • this / that / theother
  • 这/那/ theother /东西

我想在每种情况下检索最后两个字段,即:

  • this / that
  • 那个/其他
  • theother /东西

使用substring_index函数在MySQL中很容易,我看到this thread解释了如何在PHP中完成它。

有人可以帮助我在命令行中使用awk实现相同的功能吗?感谢

1 个答案:

答案 0 :(得分:4)

echo 'this/that/theother/stuff' | awk -F/ '{print $(NF-1) "/" $(NF)}'
相关问题