首页 > 解决方案 > 输出 exiv2 的特定行?

问题描述

使用exiv2,可以在终端输出图像信息。但是,它会输出几行信息:

exiv2 -ps ~/filelocation/filename.jpg

输出如下内容:

File name       : ~/filelocation/filename.jpg
File size       : 12345 Bytes
MIME type       : image/jpeg
Image size      : 800 x 600
~/filelocation/filename.jpg: No Exif data found in the file

如何命令终端仅输出图像大小数据?

我真正想要的是:

exiv2 -ps ~/filelocation/filename.jpg [some command here]

输出:

800 x 600

标签: bashmacosterminalexiv2

解决方案


尝试这个 -

exiv2 -ps ~/filelocation/filename.jpg |
  sed -n '/Image size/{ s/^.*: //; p; }'

sed-n禁止默认输出。

/pattern/逐行匹配。

{...}包装要对匹配的行执行的操作脚本。

s/^.*: //;剥离前导字符串。

p;打印值。


推荐阅读