linux - 在awk中提取列的列?
问题描述
在下面的示例中,我以 的输出结束3000 x 3000
,它可以awk
再次运行以获取宽度和高度作为变量而没有空格。
$ cat << EOF >> /tmp/test
File name : Graf3.png
File size : 84937 Bytes
MIME type : image/png
Image size : 3000 x 3000
EOF
$ cat /tmp/test | awk -F':' '/Image size/ {print $2}'
3000 x 3000
问题
有没有办法在不awk
再次调用的情况下获得宽度和高度?
解决方案
假设您想要 shell 中的值而不是 awk 变量:
$ dim=( $( awk '/Image size/{print $(NF-2), $NF}' file ) )
$ declare -p dim
declare -a dim=([0]="3000" [1]="3000")
推荐阅读
- php - 我如何添加到数组
- javascript - React 不再需要 APP.js 中的 import 语句了吗?
- c# - Panel.controls 生成时返回 null
- javascript - 如何创建动态的 React Native 组件
- angular - 如何使用外部图像
? - java - 从 Azure Key Vault 检索证书(JKS 或 PFX)
- javascript - 添加一个ID来控制显示顺序
- python - Dockerized Django 项目无法连接到主机的 postgres 数据库
- javascript - 监听另一个 JS 文件中何时调用函数。(火狐插件/扩展)
- python - 康达,我怎样才能激活一个特定的环境