【问题标题】:Output specific line for exiv2?输出 exiv2 的特定行?
【发布时间】:2018-12-05 11:57:44
【问题描述】:

使用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

【问题讨论】:

  • 你尝试了什么?将您的努力与问题一起发布
  • exiv2 -ps /filelocation/filename.jpg | grep "图像大小" | awk -F ':' '{print $2}' 这让我很接近,但我想不通。

标签: bash macos terminal exiv2


【解决方案1】:

试试这个 -

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

sed 的 -n 抑制默认输出。

/pattern/ 逐行匹配。

{...} 包装了一个动作脚本,以对匹配的行执行操作。

s/^.*: //; 去掉前导字符串。

p; 打印值。

【讨论】:

  • 这让我的终端窒息。
  • 我不得不切换到引号:exiv2 -ps filename.jpg | sed -n "/图像大小/{ s/^.*: //; p; }"
  • 我没有 exiv2,所以我把复制/粘贴弄错了,只有一个反引号。立即尝试。
猜你喜欢
  • 2019-02-26
  • 2017-04-08
  • 1970-01-01
  • 1970-01-01
  • 2018-02-11
  • 1970-01-01
  • 1970-01-01
  • 2020-12-08
  • 2014-07-22
相关资源
最近更新 更多