此表达式sed -n '/statistics:/,/^ [^ ]/ p'选择以下部分
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:来自以下文件:
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.orgChannel statistics:部分而不是Image statistics:?F 212
表达式的来源来自下面的页面http://www.imagemagick.org/Usage/compare/
发布于 2011-12-23 20:22:35
您的表达式:
sed -n '/statistics:/,/^ [^ ]/ p'
它是如何和为什么工作的?
sed的自然形式遵循语法sed 's/substitution/replacement/[g]',其中s表示替代,在全局替换结尾处有一个可选的g (如果替换文本在一行中不止一次找到)。
但sed可以做得更多。它有能力将操作限制在特定的线路上。你可以通过-
1. Specifying a line by its number.
2. Specifying a range of lines by number.
3. All lines containing a pattern.
4. All lines from the beginning of a file to a regular expression
5. All lines from a regular expression to the end of the file.
6. All lines between two regular expressions.什么是sed格式?
您的sed format采用的最后一个表单。它开始执行从包含statistics:的行到从行的开头包含两个空格的行的魔力,即__[^_],其中_是空格。i.e
sed -n '/statistics:/,/^ [^ ]/ p'
| || | | | |
--- ----------- ------ V
| | | Since we suppressed
Suppress This is This is the output, we need
output your your to invoke print
start end
range range为什么它选择Channel statistics:部分而不是Image statistics:
在原始文本行中,在Image Statistics:缩进后,从行开始有两个以上的空格,因此不会显示它们。如果你想要包括Image Statistics:,你可以把你的Address End Range修改成这样-
sed -n '/statistics:/,/^ Ren.*/p'Why -n and p?:sed在它的自然形式打印一切。每一行都放在执行所有操作的pattern space中,然后用新行打印该行。这里的操作是p,这意味着整个文本将被打印,匹配sed's范围的行将被打印两次。为了防止这种情况,我们调用-n。除非找到对-n的显式请求,否则print选项不会打印任何内容。
发布于 2011-12-07 11:19:30
如何以及为什么会工作?
见下文
什么是sed格式?
format is sed address1, address2>为什么它选择通道统计信息:部分,而不是图像统计信息:?
首先,我想说,你问题中的sed线与你的链接中的行不完全相同。应该是sed -n '/statistics:/,/^(two spaces)[^ ]/ p'
参见此示例:
kent$ cat file1
x_1
1
2
3
o
x_2
4
5
6
kent$ sed -n '/x/,/^[^ ]/p' file1
x_1
1
2
3
o
x_2我想这和你的档案很相似。
苏德做了什么?
1发现了address1的第一次匹配,即/x/,因此发现并接受了x_1。2搜索address2,/^^ /如果不匹配,打印。这个正则表达式意味着,这条线不是从空间开始的。
3 x_2从x开始,而不是空格,所以匹配address2,打印。
在x_2之后,没有更多的行匹配address1 /x/,所以x_2应该是最后一行
您的图像文件示例是相同的,唯一的区别是address2在您的情况下是从两个空格开始的。
只是我的两分钱。希望有帮助。
https://stackoverflow.com/questions/8413985
复制相似问题