亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 14315 | 回復(fù): 6
打印 上一主題 下一主題

sed完成跨行匹配的問題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2011-07-04 17:43 |只看該作者 |倒序?yàn)g覽
現(xiàn)在想用sed完成類似grep打印匹配字符串的行,grep只能打印單行匹配字符串的行,現(xiàn)在匹配字符串跨兩行了,用sed怎么實(shí)現(xiàn),具體說明代碼如下:
  1. #cat cul
  2. n1thing nothing
  3. n2thing cat and dog
  4. n3thing nothing
  5. n4thing cat and
  6. dog n5thing
  7. n6thing nothing
復(fù)制代碼
這個(gè)是要處理的文本,將要匹配的字符串是cat and dog,用數(shù)字替換nothing的o是為了表明行號(hào),以免混亂了。
可以看到第二行可以匹配cat and dog  , 第四,五行也是匹配的,現(xiàn)在要用sed實(shí)現(xiàn)打印匹配的行,打印結(jié)果如下:
  1. n2thing cat and dog
  2. n4thing cat and
  3. dog n5thing
復(fù)制代碼
如何用sed實(shí)現(xiàn)這個(gè)功能呢???

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2011-07-04 17:54 |只看該作者
曾經(jīng)有個(gè)帖子。。。搜索一下

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2011-07-04 17:58 |只看該作者

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2011-07-04 18:09 |只看該作者
暈菜,還真是看到一個(gè)地方去了,呵呵,我就是想有沒有人能寫出不一樣的出來,呵呵
下面是我把書上腳本換成命令行的模式,還有糾正那個(gè)bug  $!N
  1. #sed '/cat and dog/b;$!N;h;s/.*\n//;/cat and dog/b;g;s/ *\n/ /;/cat and dog/{g;b};g;D' cul
  2. n2thing cat and dog
  3. n4thing cat and
  4. dog n5thing
復(fù)制代碼
看看有沒有高手寫出不一樣的來。

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2011-07-04 18:48 |只看該作者
好貼……

論壇徽章:
2
射手座
日期:2014-10-10 15:59:4715-16賽季CBA聯(lián)賽之上海
日期:2016-03-03 10:27:14
6 [報(bào)告]
發(fā)表于 2011-07-04 23:25 |只看該作者
本帖最后由 yinyuemi 于 2011-07-04 23:40 編輯

回復(fù) 4# jack1007
  1. echo 'n1thing nothing
  2. n2thing cat and dog
  3. n3thing cat and
  4. n4thing cat
  5. and
  6. dog n5thing
  7. n6thing cat'  |\
  8. sed -n '/cat/{/cat and/{/cat and dog/{p;b};:a;$!N;/\ndog/{p;b};D};$!{N;/\nand/ba;D}}'
  9. n2thing cat and dog
  10. n4thing cat
  11. and
  12. dog n5thing
復(fù)制代碼

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2011-07-05 13:57 |只看該作者
嘗試著分析了一下,http://scmbob.org/sed_cross_match.html
亮點(diǎn):引入了黑哥的sed消化道理論……
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP