2013-04-05 68 views
-1

是否可以使用sed,awk或grep將行號與行號複製到destinationphp文件進行模式匹配?以
爲例,我想複製'<'(單個小於)'>之間的所有行;(單個大於逗號) from source.php file到destination.php提取與兩行之間的行號匹配的行

這是source.php enter image description here

我有代碼
SED -ne 「/''\;/wdestination.php」 source.php
這就是輸出看在截圖
enter image description here

,但我想複製與線數據線的begining匹配的行號 看起來像下面的截圖
enter image description here

+2

而不是截圖,你應該粘貼你的代碼到問題中,以便我們可以使用你的測試我們解決方案的代碼。 – dogbane 2013-04-05 08:17:56

+2

OP最後一個問題的精確重複http://stackoverflow.com/questions/15810814/copy-lines-data-between-2-patterns-in-shell-scripting – 2013-04-05 08:21:15

回答

2
sed -ne "/'</,/>'\;/{=;p}" source.php | sed 'N;s/\n/ /;wdestination.php' 

希望這是你在找什麼+

+1

是的,它的工作原理,但看中問題的中間截圖行號9, 10,11其中也打印...這是不符合我的模式 – 2013-04-05 10:52:11

+2

hi..sidharth ..我可以添加:行號和行數據之間的符號相同的第三個屏幕截圖? – 2013-04-05 11:15:30

+1

sed -ne「/''\;/{=; p}」source.php | sed'N; s/\ n /:/; wdestination.php'這將添加:符號 – 2013-04-05 12:33:33

0
awk " /'</ {printme = 1}; printme {print NR; print} ; />';/ {printme =0} " source.php | sed 'N;s/\n/ : /' > destination.php 

看看這個工作+

相關問題