2013-06-18 25 views
-4

首先拆分從多條線路的多個DATAS,我有以下數據:如何在Perl

 
********************************************************************* 
TEST CASE 
********************************************************************* 
test results for the last 1 run(s) 

TEST      TITLE         GROUP PRIO R-STAT R-TIME  VERDICT VERDICT-TEXT 
------------------------- ---------------------------------------- -------- ---- ------ ------------ -------- -------------------------------------------------- 
TESTCASE1   TC1       ABC  1 PASS 00:00:09.572 PASS  nothing 

TESTCASE2   TC2   DEF  2 PASS 00:00:01.650 PASS  nothing 


---------------------------------------------------------------------------------------------------- 
NUMBER OF : 2 
NUMBER OF TC: 2 
********************************************************************* 
VERDICT: PASS 
********************************************************************* 

我想執行行:

 
TESTCASE1   TC1       ABC  1 PASS 00:00:09.572 PASS  nothing 

TESTCASE2   TC2   DEF  2 PASS 00:00:01.650 PASS  nothing 

和分割第一行和最後線。

我該怎麼做?

補充:

對不起,來不及回覆,我想拆

********************************************************************* 
TEST CASE 
********************************************************************* 
test results for the last 1 run(s) 

TEST      TITLE         GROUP PRIO R-STAT R-TIME  VERDICT VERDICT-TEXT 
------------------------- ---------------------------------------- -------- ---- ------ ------------ -------- -------------------------------------------------- 

只是處理兩行

TESTCASE1   TC1       ABC  1 PASS 00:00:09.572 PASS  nothing 

TESTCASE2   TC2   DEF  2 PASS 00:00:01.650 PASS  nothing 
i use while loop to check line by line, the problem is it will be looped all of lines whereas i want two lines only. 
+1

這不是很清楚對我來說,你正在嘗試做什麼。你能解釋一下嗎? –

+0

不確定「執行」是什麼意思?我將遍歷每一行併爲「TESTCASE」執行正則表達式匹配。 –

+0

你是否想要在這些行上分割TEST和VERDICT-TEXT字段? – hwnd

回答

0

你可以試試這個來從文件第一和最後一行:

cat filename | grep "^TESTCASE" | sed -n '1p;$p' 
+0

我會盡量按照你的建議,謝謝 –

+0

貓命令似乎不在lib Perl中,請你幫忙指點一下perl命令嗎? –

+0

@nguyenthanh'cat'命令是一個unix shell命令。 user1244533,一個不需要'cat file | grep模式',而不是'grep模式文件'。保存一點在shell上。 – 2013-08-26 00:53:21