regex - 来自/proc/cpuinfo的grep信息

标签 regex linux ubuntu grep pattern-matching

我正在尝试使用以下命令从 Ubuntu 中的/proc/cpuinfo 中 grep 模型:

cat /proc/cpuinfo | grep 'model'

但我得到 2 行作为输出:

model       : 60
model name  : Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz

我只会得到这一行作为输出:

model       : 60

我该怎么做?

最佳答案

要仅获取第一行,只需使用 head :

cat /proc/cpuinfo | grep 'model' | head -1   # <--- This is what you realy asked

要仅获取最后一行,您可以使用 tail :

cat /proc/cpuinfo | grep 'model' | tail -1

如果你想要 n'th您可以同时使用以下行:

cat /proc/cpuinfo | grep 'model' | head -n | tail -1

关于regex - 来自/proc/cpuinfo的grep信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38585835/

相关文章:

regex - 如何从 Dart 中的字符串中仅删除符号

linux - 构建开源媒体服务器

Linux:如何将命令更改为不同的路径?

mysql - shell脚本中使用的mysql语句语法错误

ubuntu中rpcgen程序的编译器警告

regex - Putty命令查找非罗马字母命名的文件

php - 使用 javascript、PHP、MySQL 进行 html 表单处理时的安全预防措施

linux - 如何在 Unix/Linux 中获取进程的路径

android - 使用正则表达式从android中的网站文本数据中获取电话号码

linux - 在 Linux 上部署 sliver light 应用程序