Unix cut 命令从左侧提取字符串 post 从右侧开始的第二个定界符
Unix cut command to extract string from left side post 2nd dilimiter from right
剪切命令如何 return 值从右边开始到第 2 个最后一个定界符。
$ echo 'qwertyuiop.abcdefgh.1234567890.txt' | cut -d '.' -f 1,2
qwertyuiop.abcdefgh
$ echo 'qwertyuiop.1234567890.txt' | cut -d '.' -f 1,2
qwertyuiop.1234567890
$
两者的预期输出
qwertyuiop.abcdefgh
qwertyuiop
您可以使用 rev
命令反转您的字符串,然后 cut
从第三个字段到最后,在最后反转。
$ echo 'qwertyuiop.abcdefgh.1234567890.txt' | rev | cut -d '.' -f 3- | rev
qwertyuiop.abcdefgh
$ echo 'qwertyuiop.1234567890.txt' | rev | cut -d '.' -f 3- | rev
qwertyuiop
剪切命令如何 return 值从右边开始到第 2 个最后一个定界符。
$ echo 'qwertyuiop.abcdefgh.1234567890.txt' | cut -d '.' -f 1,2
qwertyuiop.abcdefgh
$ echo 'qwertyuiop.1234567890.txt' | cut -d '.' -f 1,2
qwertyuiop.1234567890
$
两者的预期输出
qwertyuiop.abcdefgh
qwertyuiop
您可以使用 rev
命令反转您的字符串,然后 cut
从第三个字段到最后,在最后反转。
$ echo 'qwertyuiop.abcdefgh.1234567890.txt' | rev | cut -d '.' -f 3- | rev
qwertyuiop.abcdefgh
$ echo 'qwertyuiop.1234567890.txt' | rev | cut -d '.' -f 3- | rev
qwertyuiop