如何使用“剪切"查找最后一个字段 [英] How to find the last field using 'cut'
本文介绍了如何使用“剪切"查找最后一个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
没有使用sed
或awk
,仅 cut
,当字段数未知或每次更改时如何获取最后一个字段线?
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
说明
-
rev
将"maps.google.com"反转为moc.elgoog.spam
-
cut
使用点(即'.')作为定界符,并选择第一个字段,即moc
- 最后,我们再次将其反转以得到
com
rev
reverses "maps.google.com" to bemoc.elgoog.spam
cut
uses dot (ie '.') as the delimiter, and chooses the first field, which ismoc
- lastly, we reverse it again to get
com
这篇关于如何使用“剪切"查找最后一个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文