简体   繁体   English

如何在Linux脚本中提取字符串中的数字和特殊字符

[英]How to extract numbers and special characters in a string in linux script

I have a string like basedir=/cp/osp/peaker/1543.23. 我有一个字符串,例如basedir = / cp / osp / peaker / 1543.23。 here i want to extract 1543.23, in linux script, could someone tell me how to do this here. 在这里我想在Linux脚本中提取1543.23,有人可以告诉我如何在这里执行此操作。

May be using sed, regex, i was unable to do. 可能正在使用sed,regex,但我做不到。 here i want 1543.23 (so i want number and special character . also). 在这里我想要1543.23(所以我也想要数字和特殊字符。)。

You could use awk . 您可以使用awk Something like 就像是

echo $basedir | awk 'BEGIN {FS="/"};{print $NF}'

That begins by setting the field separator (FS) to "/" and then printing the last field. 首先将字段分隔符(FS)设置为“ /”,然后打印最后一个字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM