- 论坛徽章:
- 1
|
本帖最后由 tank064 于 2012-12-29 18:23 编辑
- cat gggg
- 1
- 2
- 3
- aaa
- 4
- 5
- bbb
- 6
- 7
- ccc
- 1
- ddd
- 3
- eee
- 2
- fff
- 6
- 本来想匹配 1 与 3 之间的行
- awk '/1/,/3/' gggg
- 1
- 2
- 3
- 1
- ddd
- 3
- 会把匹配到的行都显示处来,但只想要特定的行.google后,查到下面这句:
- awk '{t=t RS $0}END{print gensub(/.*(1.*3).*/,"\\1",1,t)}' ggggg
- 1
- ddd
- 3
复制代码 这里的{t=t RS $0} 是什么意思,怎么用的?
t=t RS $0 即t=t+RS+$0 把字符串连接起来后赋值?
还有:
gensub(/.*(1.*3).*/,"\\1",1,t) t前面这个1是做什么用的? man awk- gsub(r, s [, t]) For each substring matching the regular expression r in the string t, substitute the
- string s, and return the number of substitutions. If t is not supplied, use $0. An &
- in the replacement text is replaced with the text that was actually matched. Use \& to
- get a literal &. (This must be typed as "\\&"; see GAWK: Effective AWK Programming for
- a fuller discussion of the rules for &’s and backslashes in the replacement text of
- sub(), gsub(), and gensub().)
复制代码 没看到这个的说明. |
|