如何利用找到的最后一个字段“腰斩”。 Linux的 [英] How to find the last field using 'cut'. Linux

查看:99
本文介绍了如何利用找到的最后一个字段“腰斩”。 Linux的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无使用'的sed''的awk'剪切,我如何得到最后一个字段时字段的数量是未知的或每行改变?

WITHOUT using 'sed' or 'awk' ONLY 'cut', how do i get the last field when the number of fields are unknown or change with every line?

推荐答案

您可以尝试这样的事:

echo 'maps.google.com' | rev | cut -d'.' -f 1 | rev

说明


  • maps.google.com的反向将 moc.elgoog.spam

  • 剪切使用点作为分隔符,并选择第一个字段,它是 MOC

  • 最后,我们再次扭转它(的提醒,感谢@汤姆),以获得 COM

  • maps.google.com's reverse will be moc.elgoog.spam
  • cut uses dot as the delimiter and chooses the first field, which is moc
  • lastly, we reverse it again (thanks for the reminder, @tom) to get com

这篇关于如何利用找到的最后一个字段“腰斩”。 Linux的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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