Shell

提取字元串的子字元串

  • February 9, 2021

如何3ccc2392-45ed-11e7-bc98-4061862b8d34:1-35942477從以下字元串中提取?

mysql-bin.000025    217141189   3ccc2392-45ed-11e7-bc98-4061862b8d34:1-35942477,

它是通過line=$(head -n 1 ./xtrabackup_binlog_info)

像這樣awk

$ line="$(head -n 1 ./xtrabackup_binlog_info)"

$ echo "$line" | awk -F'[[:blank:]]+|,' '{ print $3 }'
3ccc2392-45ed-11e7-bc98-4061862b8d34:1-35942477

使用awk

awk 'BEGIN{ FS="[,[:blank:]]+"; }; { print $(NF-1); exit; }'

引用自:https://unix.stackexchange.com/questions/633574