|
发表于 2006-3-15 11:37:36
|
显示全部楼层
Post by johnny_jiang
Yes, so my question is when it hits EOF, it just stops and does nothing or output the pattern space if any?
From the test, I think it sure outputs the pattern space and then exits.
From what I understand, the last several processes seem to be
1. hit five
2. apply N
3. read in six.
4. apply h
5. put five and six into hold space
6. apply P
7. print out the first part till newline which is five.
8. reach the end of script, since there is no "-n", then run default print. pattern space "five and six" two lines will be printed. so you see "five five six". pattern space gets cleaned.
9. read a new line in which is seven
10. apply N.
11. hit EOF. I thought sed should exit immediately w/o even printing out the pattern space, but looks like it does now. So I went to an AIX unix box and tried the same thing.
On AIX with old sed
- cat foo | sed -e 'N;P'
- one=1234
- one=1234
- two=ABCD
- three=1614.13
- three=1614.13
- four=734.25
- five=CDEF
- five=CDEF
- six=2586
复制代码
On Linux with newest sed
- cat foo | sed 'N;P'
- one=1234
- one=1234
- two=ABCD
- three=1614.13
- three=1614.13
- four=734.25
- five=CDEF
- five=CDEF
- six=2586
- seven=EFGH
复制代码
You can see the difference. When hitting EOF, the Linux ver looks like printing out the pattern space and then exit where old unix ver just exits immediately. Another comment that I made before is not correct, which was "without -n, pattern space and hold space will both be printed out". It should be "without -n, pattern space and the editing result will both be printed out" since output the pattern space is the default action of sed/awk. You guys are right, hold space will not be printed out. |
|