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

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

Chinaunix

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

求刪除特定字符片區(qū)的方法 [復(fù)制鏈接]

論壇徽章:
1
金牛座
日期:2014-05-29 15:55:47
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2014-05-21 18:48 |只看該作者 |倒序?yàn)g覽
內(nèi)容如下:

  1. lease 10.108.215.134 {
  2.   starts 2 2014/05/20 13:46:14;
  3.   ends 3 2014/05/21 13:46:14;
  4.   cltt 2 2014/05/20 13:46:14;
  5.   binding state active;
  6.   next binding state free;
  7.   rewind binding state free;
  8.   hardware ethernet 6c:e8:73:ad:32:db;
  9.   uid "\001l\350s\2552\333";
  10.   option agent.remote-id 0:23:ed:22:69:a2;
  11.   client-hostname "WR740N";
  12. }
  13. lease 10.108.215.140 {
  14.   starts 2 2014/05/20 13:46:21;
  15.   ends 3 2014/05/21 13:46:21;
  16.   cltt 2 2014/05/20 13:46:21;
  17.   binding state active;
  18.   next binding state free;
  19.   rewind binding state free;
  20.   hardware ethernet 20:dc:e6:3c:7f:4b;
  21.   uid "\001 \334\346<\177K";
  22.   option agent.remote-id a4:7a:a4:73:6e:1e;
  23.   client-hostname "WR740N";
  24. }
  25. lease 10.108.215.148 {
  26.   starts 2 2014/05/20 15:12:33;
  27.   ends 3 2014/05/21 15:12:33;
  28.   cltt 2 2014/05/20 15:12:33;
  29.   binding state active;
  30.   next binding state free;
  31.   rewind binding state free;
  32.   hardware ethernet 40:16:9f:7c:74:e7;
  33.   uid "\001@\026\237|t\347";
  34.   option agent.remote-id 0:25:f1:fd:90:7a;
  35.   client-hostname "NatRouter";
  36. }
復(fù)制代碼
我想指定刪除lease區(qū)域內(nèi)含有20:dc:e6:3c:7f:4b的整個(gè)lease {}區(qū)域,有沒有方法能實(shí)現(xiàn)?sed/perl/awk等方法都可以。

求職 : 軟件工程師
論壇徽章:
3
程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2015-10-07 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2015-12-13 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-05-05 06:20:00
2 [報(bào)告]
發(fā)表于 2014-05-21 20:28 |只看該作者
  1. #!perl

  2. use 5.010;

  3. my $text = join "", <DATA>;

  4. $text =~ s/(lease\s+[\d+\.]+\s+\{.*?\})/match_mac($1)/xmsge;
  5. say $text;

  6. sub match_mac {
  7.     my $match_text = shift;
  8.     if ($match_text =~ /20:dc:e6:3c:7f:4b/) {
  9.         return "";
  10.     }
  11.     else { return $match_text }
  12. }

  13. __DATA__
  14. lease 10.108.215.134 {
  15.   starts 2 2014/05/20 13:46:14;
  16.   ends 3 2014/05/21 13:46:14;
  17.   cltt 2 2014/05/20 13:46:14;
  18.   binding state active;
  19.   next binding state free;
  20.   rewind binding state free;
  21.   hardware ethernet 6c:e8:73:ad:32:db;
  22.   uid "\001l\350s\2552\333";
  23.   option agent.remote-id 0:23:ed:22:69:a2;
  24.   client-hostname "WR740N";
  25. }
  26. lease 10.108.215.140 {
  27.   starts 2 2014/05/20 13:46:21;
  28.   ends 3 2014/05/21 13:46:21;
  29.   cltt 2 2014/05/20 13:46:21;
  30.   binding state active;
  31.   next binding state free;
  32.   rewind binding state free;
  33.   hardware ethernet 20:dc:e6:3c:7f:4b;
  34.   uid "\001 \334\346<\177K";
  35.   option agent.remote-id a4:7a:a4:73:6e:1e;
  36.   client-hostname "WR740N";
  37. }
  38. lease 10.108.215.148 {
  39.   starts 2 2014/05/20 15:12:33;
  40.   ends 3 2014/05/21 15:12:33;
  41.   cltt 2 2014/05/20 15:12:33;
  42.   binding state active;
  43.   next binding state free;
  44.   rewind binding state free;
  45.   hardware ethernet 40:16:9f:7c:74:e7;
  46.   uid "\001@\026\237|t\347";
  47.   option agent.remote-id 0:25:f1:fd:90:7a;
  48.   client-hostname "NatRouter";
  49. }
復(fù)制代碼

論壇徽章:
1
金牛座
日期:2014-05-29 15:55:47
3 [報(bào)告]
發(fā)表于 2014-05-21 20:51 |只看該作者
能用一行實(shí)現(xiàn)嗎?
比如:perl -e "xxxxxx$MACxxxxx"
其中$MAC是一個(gè)MAC地址的變量。

求職 : 軟件工程師
論壇徽章:
3
程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2015-10-07 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2015-12-13 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-05-05 06:20:00
4 [報(bào)告]
發(fā)表于 2014-05-21 22:24 |只看該作者
本帖最后由 104359176 于 2014-05-21 22:24 編輯

  1. $ perl -0777 -ne 's/(lease\s+[\d+\.]+\s+\{.*?\})/$1=~m{20:dc:e6:3c:7f:4b}?"":$1/xmsge;
  2. print' data.txt
復(fù)制代碼

論壇徽章:
1
金牛座
日期:2014-05-29 15:55:47
5 [報(bào)告]
發(fā)表于 2014-05-22 09:06 |只看該作者
本帖最后由 iceblood 于 2014-05-22 09:13 編輯

  1. MAC="20:dc:e6:3c:75:4d"                             
  2. #perl -0777 -ne 's/(lease\s+[\d+\.]+\s+\{.*?\})/$1=~m{20:dc:e6:3c:75:4d}?"":$1/xmsge;print' tt.txt
  3. perl -0777 -ne 's/(lease\s+[\d+\.]+\s+\{.*?\})/$1=~m{$ENV{'MAC'}}?"":$1/xmsge;print' tt.txt
復(fù)制代碼
運(yùn)行失敗……請(qǐng)問我怎么樣才能把MAC這個(gè)變量代入進(jìn)去?并且讓tt.txt的內(nèi)容直接修改掉,并不需要將內(nèi)容打印出來。

論壇徽章:
2
巨蟹座
日期:2014-05-21 16:42:40巳蛇
日期:2014-05-22 08:44:29
6 [報(bào)告]
發(fā)表于 2014-05-22 13:18 |只看該作者
回復(fù) 2# 104359176
  1. my $text = join "", <DATA>;
復(fù)制代碼
這一行code的作用是什么呢?

求職 : 軟件工程師
論壇徽章:
3
程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2015-10-07 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2015-12-13 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-05-05 06:20:00
7 [報(bào)告]
發(fā)表于 2014-05-22 22:36 |只看該作者
回復(fù) 6# skyyy90


    就是把 <DATA> 里的數(shù)據(jù)合并成一個(gè)大字符串。

求職 : 軟件工程師
論壇徽章:
3
程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2015-10-07 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2015-12-13 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-05-05 06:20:00
8 [報(bào)告]
發(fā)表于 2014-05-22 22:41 |只看該作者
本帖最后由 104359176 于 2014-05-22 22:43 編輯

回復(fù) 5# iceblood


    我不明白你為什么非要一行搞定,還要用 shell 傳遞變量。

    > MAC="...."
    > perl filter.pl $MAC file.txt 這種形式不行嗎?

論壇徽章:
1
金牛座
日期:2014-05-29 15:55:47
9 [報(bào)告]
發(fā)表于 2014-05-23 09:23 |只看該作者
104359176 發(fā)表于 2014-05-22 22:41
回復(fù) 5# iceblood

代入已經(jīng)成功了。
是這么回事,因?yàn)槲业幕灸_本是shell,如果不能用perl -e這樣的解決,就相當(dāng)于我還需要額外再啟用一個(gè)腳本。

論壇徽章:
2
巨蟹座
日期:2014-05-21 16:42:40巳蛇
日期:2014-05-22 08:44:29
10 [報(bào)告]
發(fā)表于 2014-05-23 16:48 |只看該作者
回復(fù) 7# 104359176


    謝謝!
您需要登錄后才可以回帖 登錄 | 注冊(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