如何使用批处理文件从文本文件中提取行

时间:2012-06-01 07:57:58

标签: scripting

我有一个源文件,我需要过滤一些数据以便进一步处理......

源代码如下

(C) SRC Secure Solutions bv                     iMenu400 Authorised Options for User         28/05/12  15:39:36       Page      1
=====================================================================================================================================
               *                                                                                                       *
* * * * * * * * *      User information  . . . . . : User name . . . . . . . . . : ABAX                             * * * * * * * * *
               *                                      User text . . . . . . . . . : Beatrice Raffaele                  *
                                                      Begin menu  . . . . . . . . : *NONE
                                                      Group jobs  . . . . . . . . :  15
                                                      End group jobs  . . . . . . : *NO
                                                      Command line on menus . . . : *NO
                                                      Attention-key program . . . : *ACTIVE
                                                      Reference user  . . . . . . : OPERATOR
=====================================================================================================================================
Menu information:      Menu  . . . . . . . . . . . : ITOP
                        Menu text . . . . . . . . . : ITOP menu for the IBM operators
                        User authority  . . . . . . : *REFUSER
                        Reference user authority  . : *USE
Option   Option                                           User          Ref.user      Group               Date      Time      Number
number   text                                             authority     authority     job      Activated  used      used     acesses
_____________________________________________________________________________________________________________________________________
    1     Job Schedul. BOD 06am EOD:20pm                   *REFUSER      *USE          *NO     *YES
    9     WRKJOBJS                                         *REFUSER      *USE          *NO     *YES        14/05/12  11:54:37     209
   10     Work with Job Scheduler (BOD)                    *REFUSER      *USE          *NO     *YES        14/05/12   5:04:37     156
   11     Work with Job Scheduler (EOD)                    *REFUSER      *USE          *NO     *YES        11/05/12  23:27:57     248
   12     Check JS History                                 *REFUSER      *USE          *NO     *YES
   13     WRKJOBSCDE                                       *REFUSER      *USE          *NO     *YES        29/02/12   4:10:25       2
   15     Save and Restore                                 *REFUSER      *USE          *NO     *YES
   20     Save Objects       (SAVOBJ)                      *REFUSER      *USE          *NO     *YES
   21     Restore Object     (RSTOBJ)                      *REFUSER      *USE          *NO     *YES
   22     Save Library       (SAVLIB)                      *REFUSER      *USE          *NO     *YES
   23     Restore Library    (RSTLIB)                      *REFUSER      *USE          *NO     *YES
   24     Save restore obj   (SAVRSTOBJ)                   *REFUSER      *USE          *NO     *YES
   25                                                      *REFUSER      *USE          *NO     *YES
   27     Work with commands                               *REFUSER      *USE          *NO     *YES
   28     Work with BRMS     (WRKMEDIBRM                   *REFUSER      *USE          *NO     *YES
   29     Work with object   (WRKOBJ)                      *REFUSER      *USE          *NO     *YES        29/02/12  23:38:06       1
   30     Active Jobs        (WRKACTJOB)                   *REFUSER      *USE          *NO     *YES        28/05/12  12:11:10     675
   31     MQSeries           (WRKMQM)                      *REFUSER      *USE          *NO     *YES        25/10/11  21:15:30       5
   32     Configurat.status  (WRKCFGSTS)                   *REFUSER      *USE          *NO     *YES
   33     Submitted Jobs     (WRKSBMJOB)                   *REFUSER      *USE          *NO     *YES         3/08/11   4:03:06       1
   34     Object Locks       (WRKOBJLCK)                   *REFUSER      *USE          *NO     *YES         7/06/11  23:53:36       9
   35     Work with Job      (WRKJOB)                      *REFUSER      *USE          *NO     *YES        14/05/12   5:08:32      25
   36     Work with Writers  (WRKWTR)                      *REFUSER      *USE          *NO     *YES
   37     Output Queues      (WRKOUTQ)                     *REFUSER      *USE          *NO     *YES
   38     Spool Files        (WRKSPLF)                     *REFUSER      *USE          *NO     *YES        29/02/12   4:58:54      10
   39                                                      *REFUSER      *USE          *NO     *YES
   40     Device Description (WRKDEVD)                     *REFUSER      *USE          *NO     *YES         8/01/12  20:53:13       4
   41     Work with Libraries(WRKLIB)                      *REFUSER      *USE          *NO     *YES        27/03/12  15:28:43       5
   42     With Subsystems    (WRKSBS)                      *REFUSER      *USE          *NO     *YES         8/01/12  18:18:51      10
(C) SRC Secure Solutions bv                     iMenu400 Authorised Options for User         28/05/12  15:39:36       Page      2
=====================================================================================================================================
Option   Option                                           User          Ref.user      Group               Date      Time      Number
number   text                                             authority     authority     job      Activated  used      used     acesses
_____________________________________________________________________________________________________________________________________
              *                                                                                                       *
* * * * * * * * *      User information  . . . . . : User name . . . . . . . . . : AGNESP                           * * * * * * * * *
               *                                      User text . . . . . . . . . : AGNES L Q POOI                     *
                                                      Begin menu  . . . . . . . . : MAIN
                                                      Group jobs  . . . . . . . . :  15
                                                      End group jobs  . . . . . . : *NO
                                                      Command line on menus . . . : *NO
                                                      Attention-key program . . . : *ACTIVE
                                                      Reference user  . . . . . . : *MULTIPLE
Reference User
_____________________________________________________________________________________________________________________________________
ALLUSR      Main Menu User                                         GRPBOSECA   Securities Admin.
GRPBOSECI   Securities Admin.                                      GRPBOSECU   Securities Admin



=====================================================================================================================================
               *                                                                                                       *
* * * * * * * * *      User information  . . . . . : User name . . . . . . . . . : SGKANT                           * * * * * * * * *
               *                                      User text . . . . . . . . . : SUNNY SEOW PENG KANG               *
                                                      Begin menu  . . . . . . . . : MAIN
                                                      Group jobs  . . . . . . . . :  15
                                                      End group jobs  . . . . . . : *NO
                                                      Command line on menus . . . : *NO
                                                      Attention-key program . . . : *ACTIVE
                                                      Reference user  . . . . . . : *MULTIPLE
Reference User
_____________________________________________________________________________________________________________________________________
ALLUSR      Main Menu User                                         GRPMKTFO    Front Office Mkting
=====================================================================================================================================
Menu information:      Menu  . . . . . . . . . . . : MAIN
                        Menu text . . . . . . . . . : ABN Amro Singapore
                        User authority  . . . . . . : *REFUSER
                        Reference user authority  . : *USE
Option   Option                                           User          Ref.user      Group               Date      Time      Number
number   text                                             authority     authority     job      Activated  used      used     acesses
_____________________________________________________________________________________________________________________________________
   33     Front Office Main Menu                           *REFUSER      *USE          *NO     *YES        10/04/12  18:15:34     229
   90     SIGNOFF                                          *REFUSER      *USE          *NO     *YES
=====================================================================================================================================
Menu information:      Menu  . . . . . . . . . . . : MK01
                        Menu text . . . . . . . . . : Front Office Marketing - RM Main Menu
                        User authority  . . . . . . : *REFUSER
                        Reference user authority  . : *USE
Option   Option                                           User          Ref.user      Group               Date      Time      Number
number   text                                             authority     authority     job      Activated  used      used     acesses
_____________________________________________________________________________________________________________________________________
    1     Clients Management                               *REFUSER      *USE          *NO     *YES        10/04/12  18:15:35     206
    2     Securities Management                            *REFUSER      *USE          *NO     *YES
    3     Tables Management                                *REFUSER      *USE          *NO     *YES
    4     Rates Management                                 *REFUSER      *USE          *NO     *YES        15/11/10  14:33:53      25
    5     Treasury Management                              *REFUSER      *USE          *NO     *YES
    6     Statistics and Reports                           *REFUSER      *USE          *NO     *YES        14/05/10  11:25:32       1
    7     Mirage                                           *REFUSER      *USE          *NO     *YES        22/04/10   9:03:43       3
   80     Change Passwords                                 *REFUSER      *USE          *NO     *YES
   81     View Reports                                     *REFUSER      *USE          *NO     *YES
   90     SIGNOFF                                          *REFUSER      *USE          *NO     *YES        21/04/10  10:07:11       1
(C) SRC Secure Solutions bv                     iMenu400 Authorised Options for User         28/05/12  15:39:36       Page   1728
=====================================================================================================================================
=====================================================================================================================================

所需的输出>>

(C) SRC Secure Solutions bv                     iMenu400 Authorised Options for User         28/05/12  15:39:36       Page      1
=====================================================================================================================================
               *                                                                                                       *
* * * * * * * * *      User information  . . . . . : User name . . . . . . . . . : ABAX                             * * * * * * * * *
               *                                      User text . . . . . . . . . : Beatrice Raffaele                  *
                                                      Begin menu  . . . . . . . . : *NONE
                                                      Group jobs  . . . . . . . . :  15
                                                      End group jobs  . . . . . . : *NO
                                                      Command line on menus . . . : *NO
                                                      Attention-key program . . . : *ACTIVE
                                                      Reference user  . . . . . . : OPERATOR
=====================================================================================================================================

              *                                                                                                       *
* * * * * * * * *      User information  . . . . . : User name . . . . . . . . . : AGNESP                           * * * * * * * * *
               *                                      User text . . . . . . . . . : AGNES L Q POOI                     *
                                                      Begin menu  . . . . . . . . : MAIN
                                                      Group jobs  . . . . . . . . :  15
                                                      End group jobs  . . . . . . : *NO
                                                      Command line on menus . . . : *NO
                                                      Attention-key program . . . : *ACTIVE
                                                      Reference user  . . . . . . : *MULTIPLE
Reference User
_____________________________________________________________________________________________________________________________________
ALLUSR      Main Menu User                                         GRPBOSECA   Securities Admin.
GRPBOSECI   Securities Admin.                                      GRPBOSECU   Securities Admin





              *                                                                                                       *
* * * * * * * * *      User information  . . . . . : User name . . . . . . . . . : SGKANT                           * * * * * * * * *
               *                                      User text . . . . . . . . . : SUNNY SEOW PENG KANG               *
                                                      Begin menu  . . . . . . . . : MAIN
                                                      Group jobs  . . . . . . . . :  15
                                                      End group jobs  . . . . . . : *NO
                                                      Command line on menus . . . : *NO
                                                      Attention-key program . . . : *ACTIVE
                                                      Reference user  . . . . . . : *MULTIPLE
Reference User
_____________________________________________________________________________________________________________________________________
ALLUSR      Main Menu User                                         GRPMKTFO    Front Office Mkting
=====================================================================================================================================

我的方法(伪代码)就像这样

   for /f "delims=" %%a in ('type "file.txt" ^|find ". . :"') do (
:: print the line 
:: but if find "Menu information:" OR "Menu text" OR "User authority  " OR Reference user authority >> THEN IGNORE.

then  for /f "delims=" %%a in ('type "file.txt" ^|find "ALLUSR"') do (
print the line...

then for /f "delims=" %%a in ('type "file.txt" ^|find "GRP"') do (
print the line...

我想知道如何实现批处理文件代码,因为我是批处理脚本的新手。

任何人都可以提供帮助?感谢..

0 个答案:

没有答案