list - How to get a comma-separated list of pages with color in a PDF?
问题描述
Consider this PDF 'colorpages.pdf' linked here
I have two commands to know a) how many colored pages I have in my PDF b) on which page color is used.
For a) I use
gs -o - -sDEVICE=inkcov colorpages.pdf | grep -v "^ 0.00000 0.00000 0.00000" | grep "^ " | wc
and I get back a number (total amount of pages with color).
For b) I use
gs -o - -sDEVICE=inkcov colorpages.pdf |tail -n +5 |sed '/^Page*/N;s/\n//' |sed -E '/Page [0-9]+ 0.00000 0.00000 0.00000 / d'
which gives me a nice list with color information; e.g.
Page 1 0.00000 0.00000 0.00000 0.99454 CMYK OK
Page 2 0.00000 0.99228 0.00000 0.00000 CMYK OK
Page 3 0.99222 0.00000 0.00000 0.00000 CMYK OK
Page 4 0.99289 0.99289 0.99289 0.99289 CMYK OK
Page 5 0.99316 0.99316 0.00000 0.00000 CMYK OK
Page 6 0.99130 0.99130 0.99130 0.99130 CMYK OK
Page 7 0.00000 0.00000 0.00000 0.99392 CMYK OK
Page 8 0.00000 0.00000 0.00000 0.99189 CMYK OK
Page 9 0.00000 0.00000 0.00000 0.99128 CMYK OK
Page 10 0.00000 0.00000 0.98594 0.00000 CMYK OK
Page 11 0.00000 0.98908 0.98908 0.00000 CMYK OK
Page 12 0.00000 0.00000 0.00000 0.98682 CMYK OK
But what I need (additionally) is a comma separated list of all the pages color is used.
Following up
The command
gs -o - -sDEVICE=inkcov colorpages.pdf |tail -n +5 |sed '/^Page*/N;s/\n//' |sed -E '/Page [0-9]+ 0.00000 0.00000 0.00000 / d' | awk '$3!=0 && $4!=0 && $5!=0{if(length(colored))colored=colored","$2;else colored=$2} END{print colored}'
gives me the following list 1,2,3,4,5,6,7,8,9,10,11,12
.
But it should be 2,3,4,5,6,10,11.
解决方案
awk '$3!=0{if(length(colored))colored=colored","$2;else colored=$2} END{print colored}'
2,5,7
-->echo "$x"
Page 1 0.00000 0.00000 0.00000 0.12395 CMYK OK
Page 2 0.00016 0.00035 0.00017 0.47061 CMYK OK
Page 3 0.00000 0.00000 0.00000 0.34571 CMYK OK
Page 4 0.00000 0.00000 0.00000 0.32637 CMYK OK
Page 5 0.00016 0.00035 0.00017 0.47061 CMYK OK
Page 6 0.00000 0.00000 0.00000 0.63394 CMYK OK
Page 7 0.00016 0.00035 0.00017 0.47061 CMYK OK
echo "$x" |awk '$3!=0{if(length(colored))colored=colored","$2;else colored=$2} END{print colored}'
2,5,7
如果 col 3,4,5 需要0
调用有颜色的行,那么:(你可以玩弄这些条件)
awk '$3!=0 && $4!=0 && $5!=0{if(length(colored))colored=colored","$2;else colored=$2} END{print colored}'
更新:
您可以使用 OR 运算符(||
)来获得问题中提到的所需结果。
echo "$x" |awk '$3!=0 || $4!=0 || $5!=0{if(length(colored))colored=colored","$2;else colored=$2} END{print colored}'
2,3,4,5,6,10,11
推荐阅读
- reactjs - 为什么我无法使用 axios 调用获取数据?
- c++ - 对 `__imp_glClear' 的未定义引用
- symfony - Easy Admin 不显示关系
- javascript - 如何通过纯 JavaScript 定义第 n 个父元素?
- php - 如何使用 BOOTSTRAP 电子邮件发送 HTML
- java - Spring Webflux Webclient:窃听日志记录问题
- asp.net - 工具栏中的 NavigateUrl
- typescript - Spread only overlapping elements of an object into a new one with TypeScript
- msbuild - 构建步骤后在 Cake 脚本中公开 MSBuild 属性
- c - READELF - 如何在符号名称后添加“@GLIBX_XXX”