如何在perl中从多行拆分多个数据

时间:2013-06-18 16:19:11

标签: 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 :(得分:0)

您可以尝试从档案中获取第一行和最后一行:

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