更新时间:2023-12-05 17:50:16
多种方式,一种选择:
str=abc.out
外壳:
echo ${str%.*}
格雷普:
echo $str | grep -o '^[^\.]*'
Sed:
echo $str | sed -E 's/(.*?)\..*/\1/'
awk:
echo $str | awk -F. '{print $1}'
-F.
表示将字符串拆分为 .$1
表示第一列.
-F.
means split the string by . and $1
means the first column.
剪切:
echo $str |切-d.-f1
所有输出:
abc