linux - 从 .dat 文件读取时如何消除除必需数字以外的所有内容?

标签 linux unix sh

我有一个 .dat 文件,它包含如下数据:

 count ------- 234 (1 row)

我想检索唯一的 234 作为整数,并想存储在 Shell 脚本文件的变量中。

我使用了以下命令:

WORKFLOW_STATUS_COUNT=`cat status_count.dat | tr -d " "`

但它的输出为:

count ------- 234 (1 row)

但预期是 234 整数值。

最佳答案

您可以使用:

WORKFLOW_STATUS_COUNT=`cat status_count.dat | cut -d" " -f 3 `

cut 使用空格键 分隔符拆分行,然后仅选择第三列

如果文件来自 Windows 源,您可以尝试使用 dos2unix:

WORKFLOW_STATUS_COUNT=`cat status_count.dat | dos2unix | cut -d" " -f 3 `

关于linux - 从 .dat 文件读取时如何消除除必需数字以外的所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38564904/

相关文章:

windows - 找不到适合 Windows 的 git gui。有人知道吗?

c++ - 在 C++ 中确定系统停止

ruby - 如何从 Unix 将 DOS 行结尾写入文件

linux - 对返回状态代码 shell 脚本的使用感到困惑?

linux - .sh 文件中的 Tar 搜索结果

linux - 多个进程中的pthread_mutex_t...谁破坏了它?

java - 哪个系统调用返回连接到 Linux 系统的设备列表?

winapi - windows上的fadvise/madvise等价物是什么?

shell - 获取两个参数之间的内容,参数在一个文件中多次出现

Bash 脚本 : Error, 文件意外结束