2014-12-03 87 views
-2

這是本主題我的問題真實案例(Remove all character after matched character如何獲得第一列和最後一個數字列

http://example.com/read.php/984.htm" target="_blank"> (đảo hải tặc) chap      499-3 [TV] 
http://example.com/read.php/983.htm" target="_blank"> (đảo hải tặc) chap      499-2 [TV] 
http://example.com/read.php/982.htm" target="_blank"> (đảo hải tặc) chap      499 [TV] 
http://example.com/read.php/981.htm" target="_blank"> chapter 498 TV :11 siêu      tân tinh 
http://example.com/read.php/980.htm" target="_blank"> chapter 497 TV :cuộc      phiêu lưu tại đảo bong bóng 
http://example.com/read.php/979.htm" target="_blank"> (đảo hải tặc) chap      496 [TV] 
http://example.com/read.php/978.htm" target="_blank"> chapter 495 
http://example.com/read.php/977.htm" target="_blank"> (đảo hải tặc)      494 
http://example.com/read.php/976.htm" target="_blank"> (đảo hải tặc) section      493 [TV] 
http://example.com/read.php/975.htm" target="_blank">s chapter 492 TV " Duval      mặt nạ sắt" 
http://example.com/read.php/973.htm" target="_blank"> chap 490: Trở vỠnơi      ấy. 
http://example.com/read.php/972.htm" target="_blank"> (đảo hải tặc) chap      489 
http://example.com/read.php/971.htm" target="_blank"> 488 :Bài hát của      cuộc sống 
http://example.com/read.php/970.htm" target="_blank"> (đảo hải tặc) chap      487 
http://example.com/read.php/969.htm" target="_blank"> chao 486 Cây Äàn      DÆ°Æ¡ng Cầm 
http://example.com/read.php/968.htm" target="_blank"> (đảo hải tặc) chap      485 
http://example.com/read.php/967.htm" target="_blank"> Part 484 
http://example.com/read.php/966.htm" target="_blank"> (đảo hải tặc) 483 
http://example.com/read.php/965.htm" target="_blank"> chap 482 
http://example.com/read.php/963.htm" target="_blank"> chapter 480 
http://example.com/read.php/962.htm" target="_blank"> Chap 479 
http://example.com/read.php/961.htm" target="_blank"> Chap 478 
http://example.com/read.php/960.htm" target="_blank"> (đảo hải tặc) chap      477 
http://example.com/read.php/959.htm" target="_blank"> (đảo hải tặc) chap      476 
http://example.com/read.php/958.htm" target="_blank"> (đảo hải tặc) chap      475 
http://example.com/read.php/957.htm" target="_blank"> (đảo hải tặc) chap      474 
http://example.com/read.php/956.htm" target="_blank"> (đảo hải tặc) chap      473 
http://example.com/read.php/955.htm" target="_blank"> (đảo hải tặc) chap      472 
http://example.com/read.php/954.htm" target="_blank"> chap 471 
http://example.com/read.php/953.htm" target="_blank"> chap 470 
http://example.com/read.php/952.htm" target="_blank"> chap 469 (tiếp theo      NXB) 
http://example.com/post/6050/" target="_blank"> chap-0 (Strong World) 

如何刪除所有字符後「號X」第一columd和「數之間+ X」 ......我想我的輸出這樣的

http://example.com/read.php/982.htm 499-3 
http://example.com/read.php/982.htm 499-2 
http://example.com/read.php/982.htm 499 
http://example.com/read.php/981.htm 498 
http://example.com/read.php/980.htm 497 
http://example.com/read.php/979.htm 496 
http://example.com/read.php/978.htm 495 
http://example.com/read.php/977.htm 494 

注: 「數x」 有時是499-1 499-2 499-3

+4

編寫代碼將是一個良好的開端... – 2014-12-03 17:52:06

+0

潛在求解:注意'數x'並不總是最後元素在線上。祝你們好運。 – shellter 2014-12-03 18:17:47

+1

如果數字x有時是499-1 499-2 499-3,那麼在你的樣本輸入中顯示那些,這就是它的意義。還要確保您的預期輸出完全符合您期望的輸入 - 它在我看來像是缺少一些行。 – 2014-12-03 18:50:08

回答

0

在Perl中:

perl -ne '$_ =~ s/(.*htm)"[^0-9]*([-0-9]*).*/$1 $2/; print $_' < mydata 
0

使用

perl -pe 's/(?<=htm)\D*(\d+).*/ $1/' file 
1

中美戰略經濟對話

sed -n 's/\(.*htm\)"[^0-9]*\([-0-9]*\).*/\1 \2/p' infile 
相關問題