使用 sed 基于预定义标头选择文件的部分
选择以下部分
Channel statistics:
Red:
min: 0 (0)
max: 255 (1)
mean: 114.237 (0.447987)
standard deviation: 115.1 (0.451372)
kurtosis: -1.92845
skewness: 0.0962143
Green:
min: 0 (0)
max: 255 (1)
mean: 113.318 (0.444384)
standard deviation: 113.041 (0.443298)
kurtosis: -1.94057
skewness: 0.0648024
Blue:
min: 0 (0)
max: 255 (1)
mean: 111.01 (0.435332)
standard deviation: 110.498 (0.433324)
kurtosis: -1.92769
skewness: 0.0747213
Image statistics:
此表达式 sed -n '/statistics:/,/^ [^ ]/ p'
从以下文件中
Image: /tmp/magick-XXpWFUXl
Base filename: -
Format: MIFF (Magick Image File Format)
Class: DirectClass
Geometry: 480x360+0+0
Resolution: 72x72
Print size: 6.66667x5
Units: Undefined
Type: TrueColor
Base type: TrueColor
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
Channel statistics:
Red:
min: 0 (0)
max: 255 (1)
mean: 114.237 (0.447987)
standard deviation: 115.1 (0.451372)
kurtosis: -1.92845
skewness: 0.0962143
Green:
min: 0 (0)
max: 255 (1)
mean: 113.318 (0.444384)
standard deviation: 113.041 (0.443298)
kurtosis: -1.94057
skewness: 0.0648024
Blue:
min: 0 (0)
max: 255 (1)
mean: 111.01 (0.435332)
standard deviation: 110.498 (0.433324)
kurtosis: -1.92769
skewness: 0.0747213
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 84.6411 (0.331926)
standard deviation: 109.309 (0.428662)
kurtosis: -1.6052
skewness: 0.582669
Rendering intent: Undefined
Interlace: None
Background color: white
Border color: rgb(223,223,223)
Matte color: grey74
Transparent color: black
Compose: Over
Page geometry: 480x360+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
date:create: 2011-12-07T12:33:31+02:00
date:modify: 2011-12-07T12:33:31+02:00
signature: f2adc51db916151ddcc5b206a8921eec0234efa1eeb7484c0046506b749bc392
Artifacts:
verbose: true
Tainted: False
Filesize: 179KB
Number pixels: 173KB
Pixels per second: 0b
User time: 0.000u
Elapsed time: 0:01.000
Version: ImageMagick 6.6.0-4 2011-06-15 Q16 http://www.imagemagick.org
- :它如何以及为何工作?
- sed 格式是什么?
- 为什么它选择
Channel stats:
部分而不是Image stats:
?
表达式的来源取自以下页面 http://www.imagemagick.org/Usage/compare /
This expression sed -n '/statistics:/,/^ [^ ]/ p'
selects the following section
Channel statistics:
Red:
min: 0 (0)
max: 255 (1)
mean: 114.237 (0.447987)
standard deviation: 115.1 (0.451372)
kurtosis: -1.92845
skewness: 0.0962143
Green:
min: 0 (0)
max: 255 (1)
mean: 113.318 (0.444384)
standard deviation: 113.041 (0.443298)
kurtosis: -1.94057
skewness: 0.0648024
Blue:
min: 0 (0)
max: 255 (1)
mean: 111.01 (0.435332)
standard deviation: 110.498 (0.433324)
kurtosis: -1.92769
skewness: 0.0747213
Image statistics:
From the following file:
Image: /tmp/magick-XXpWFUXl
Base filename: -
Format: MIFF (Magick Image File Format)
Class: DirectClass
Geometry: 480x360+0+0
Resolution: 72x72
Print size: 6.66667x5
Units: Undefined
Type: TrueColor
Base type: TrueColor
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
Channel statistics:
Red:
min: 0 (0)
max: 255 (1)
mean: 114.237 (0.447987)
standard deviation: 115.1 (0.451372)
kurtosis: -1.92845
skewness: 0.0962143
Green:
min: 0 (0)
max: 255 (1)
mean: 113.318 (0.444384)
standard deviation: 113.041 (0.443298)
kurtosis: -1.94057
skewness: 0.0648024
Blue:
min: 0 (0)
max: 255 (1)
mean: 111.01 (0.435332)
standard deviation: 110.498 (0.433324)
kurtosis: -1.92769
skewness: 0.0747213
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 84.6411 (0.331926)
standard deviation: 109.309 (0.428662)
kurtosis: -1.6052
skewness: 0.582669
Rendering intent: Undefined
Interlace: None
Background color: white
Border color: rgb(223,223,223)
Matte color: grey74
Transparent color: black
Compose: Over
Page geometry: 480x360+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
date:create: 2011-12-07T12:33:31+02:00
date:modify: 2011-12-07T12:33:31+02:00
signature: f2adc51db916151ddcc5b206a8921eec0234efa1eeb7484c0046506b749bc392
Artifacts:
verbose: true
Tainted: False
Filesize: 179KB
Number pixels: 173KB
Pixels per second: 0b
User time: 0.000u
Elapsed time: 0:01.000
Version: ImageMagick 6.6.0-4 2011-06-15 Q16 http://www.imagemagick.org
- How and why does it work?
- What is the sed format ?
- Why it selects the
Channel statistics:
section but not theImage statistics:
?
The source of the expression is taken from the following page http://www.imagemagick.org/Usage/compare/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它是如何工作的以及为什么工作?
sed
的自然形式遵循语法sed 's/substitution/replacement/[g]'
,其中s
代表 substitution< /strong> 以及结尾处的可选g
用于全局替换(如果在一行中多次找到替换文本。但是
sed
可以它有能力限制操作。您可以通过 -What is the sed format ?
您的
sed format
采用最后一种形式 来实现这一点。 >statistics: 到从行开头恰好包含两个空格的行,即__[^_]
其中_
是空格。选择
频道 :
?stats: 部分,但不是
Image stats 行,因此它们不会显示。如果您想包含
图像统计信息:
,您可以修改您的地址结束范围
,如下所示 -为什么 -n 和 p?:
sed
以其自然形式打印所有内容。每行都放在模式空间
中,在该空间上执行所有操作,然后用新行打印该行。这里的操作是p
,这意味着将打印整个文本,并且与sed的
范围匹配的行将被打印两次。为了防止这种情况,我们调用-n
。除非找到对print
的显式请求,否则-n
选项不会打印任何内容。How and why does it work?
sed
in it's natural form follows the syntaxsed 's/substitution/replacement/[g]'
wheres
is for substitution and an optionalg
at the end for global replacement (if substitution text is found more than once in a line.But
sed
can do much more. It has the ability to restrict the operation to certain lines. You can do that by -What is the sed format ?
Your
sed format
takes the last form. It starts performing it's magic from the line that containsstatistics:
to the line that contains exactly two spaces from the beginning of the line i.e__[^_]
where_
is the space. i.eWhy it selects the
Channel statistics:
section but not theImage statistics:
?In your original text lines after
Image Statistics:
are indented and have more than 2 spaces from the beginning of the line as a result they are not displayed. If you want to includeImage Statistics:
you can modify yourAddress End Range
to be like this -Why -n and p?:
sed
in it's natural form prints everything. Each line is put in thepattern space
upon which all actions are performed on it and then the line is printed with a new line. The action over here isp
which means entire text will be printed and the lines that matches thesed's
range will be printed twice. To prevent this we invoke the-n
. The-n
option will not print anything unless an explicit request toprint
is found.见下文
>为什么它选择“通道统计:”部分而不是“图像统计:”?
首先,我想说您问题中的 sed 行与链接中的行不完全相同。它应该是
sed -n '/statistics:/,/^(two space)[^ ]/ p'
请参阅此示例:
我认为这与您的文件非常相似。
sed 是做什么的?
是相同的,唯一的区别是您的情况下的地址2是以两个空格开头的行。
只是我的 2 美分。希望有帮助。
see below
> Why it selects the Channel statistics: section but not the Image statistics: ?
first, I would say that the sed line in your question is not exactly the same as the line in your link. it should be
sed -n '/statistics:/,/^(two spaces)[^ ]/ p'
see this example:
I think this would be quite similar as your file.
what sed does?
your image file example is the same, only difference is address2 in your case is line starting with two spaces.
just my 2 cents. hope helpful.