String 在UNIX上解析数字文件

String 在UNIX上解析数字文件,string,parsing,unix,String,Parsing,Unix,正在寻找从文件最后一行提取数字的更好方法。 样本内容: # Provider added by blah # security.provider.3=org.bouncycastle145.jce.provider.BouncyCastleProvider # # Provider added by blah # security.provider.4=org.bouncycastle145.jce.provider.BouncyCastleProvider # # Provider added

正在寻找从文件最后一行提取数字的更好方法。 样本内容:

# Provider added by blah
#
security.provider.3=org.bouncycastle145.jce.provider.BouncyCastleProvider
#
# Provider added by blah
#
security.provider.4=org.bouncycastle145.jce.provider.BouncyCastleProvider
#
# Provider added by blah
#
security.provider.79=org.bouncycastle145.jce.provider.BouncyCastleProvider
我想解析文件中的最后一行,并在以下内容之后返回数字:
security.provider.

这就是我正在使用的,它似乎只适用于以下数字之后的第一个数字:
security.provider.

tail -1 filename | cut -c19
我知道我可以使用:

tail -1 filename | cut -c19,20 
但是我不知道数字是一位数还是两位数,等等。

您可以将sed用作:

tail -1 file | sed -r 's/security\.provider\.([0-9]+).*/\1/'

假设您的最后一行始终是“security.provider.xxx=”并且您想要xxx:

$ sed -n \$p file | cut -d= -f 1 | cut -d. -f 3 $sed-n\$p文件| cut-d=-f1 | cut-d-F3
您可以使用一个
sed
一行程序来完成此操作:

sed -ne '$s/security\.provider\.\([0-9]\+\).*/\1/p' <file>
sed-ne'$s/security\.provider\.\([0-9]\+\)./\1/p'