linux - 如何使用 awk 去掉输出最后一列的字符?

标签 linux bash shell awk

我的命令输出如下所示:

XYZ Server Version 15.2.8 (10095.48)

如何使用 awk 只打印 10095? (可能有 4 或 6 个数字,而不是 5 个)

此外,如果我有如下输出:

XYZ Server Version: 12.2.4.8638

如何打印点后面的输出?它应该看起来像这样:8638

最佳答案

您可以使用-F来定义“字段分隔符”:

How can I use awk in order to print only 10095? (there might be 4 or 6 numbers instead of 5)

echo "XYZ Server Version 15.2.8 (10095.48)" | awk -F'(' '{print $2}' | awk -F')' '{print $1}' | awk -F'.' '{print $1}'

How can I print the output that follows the dot? It should look like this: 8638

echo "XYZ Server Version: 12.2.4.8638" | awk -F'.' '{print $NF}'

关于linux - 如何使用 awk 去掉输出最后一列的字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57571081/

相关文章:

git - 您如何使用存储删除然后恢复非索引更改,而不会在 git 中发生 merge 冲突?

bash - 如何在 Bash shell 脚本中检查目录是否存在?

Javascript自动重启

c - 如何在线程中等待信号?

python - 如何从命令行使包可执行?

linux - 检测到反向(或先前应用的)补丁!假设-R? [n]

c++ - MinGW 下 windows 中的 Protobuf

swift - 在 swift 中使用 Process() 符号化崩溃时出现运行时错误

linux - 从配置文件中的 shell 脚本读取变量

linux - 如何在 shell 脚本变量中使用 {old,new}name?