MSFN Forum: how to use batch file to extract lines from text file - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

how to use batch file to extract lines from text file Rate Topic: -----

#1 User is offline   jasonchia 

  • Group: Members
  • Posts: 1
  • Joined: 31-May 12
  • OS:XP Home
  • Country: Country Flag

Posted 31 May 2012 - 10:05 PM

hi people,

i am writing a script to filter desired data from a source file.
the script is like this

my script
findstr /B "(C) SRC Secure Solutions bv " | findstr /B "===========" | findstr /B "               * " | findstr /B "* * * * * * * * *  " > (and findstr continue)test.txt


i try to use findstr?B command which it match the beginning of the line..


input

(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
 =====================================================================================================================================
               *                                                                                                       *
 * * * * * * * * *      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
 =====================================================================================================================================
 Menu information:      Menu  . . . . . . . . . . . : BO09
                        Menu text . . . . . . . . . : BO Ops Exceptional Functions 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     Exceptional Functions                            *REFUSER      *USE          *NO     *YES
   90     SIGNOFF                                          *REFUSER      *USE          *NO     *YES
 =====================================================================================================================================
 Menu information:      Menu  . . . . . . . . . . . : BO09001
                        Menu text . . . . . . . . . : Exceptional Functions
                        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     Re-activate                                      *REFUSER      *USE          *NO     *YES
    2     Transfer Order In "BAD" Status                   *REFUSER      *USE          *NO     *YES
   90     SIGNOFF                                          *REFUSER      *USE          *NO     *YES
 =====================================================================================================================================
              *                                                                                                       *
 * * * * * * * * *      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
 =====================================================================================================================================


output

(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
=====================================================================================================================================




i think it doesn't recognize * and space ?!
So, any way to extract the required data..
i also think about using findstr /v, but this will result in more command which is not efficient.
anyone can guide me along about how to implement the code in a more efficiency,,
thanks


#2 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,436
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 01 June 2012 - 08:42 AM

View Postjasonchia, on 31 May 2012 - 10:05 PM, said:

So, any way to extract the required data..

Can you detail which specific data are you trying to extract? :unsure:

jaclaz

#3 User is offline   bphlpt 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,082
  • Joined: 12-May 07

Posted 01 June 2012 - 09:50 AM

Are you trying to put in "input" and get out "output"? Is that exact output form required (Why?), or would you rather have a more concise summary of the specific fields you are interested in?

Cheers and Regards

#4 User is offline   allen2 

  • Not really Newbie
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,736
  • Joined: 13-January 06

Posted 01 June 2012 - 03:10 PM

Using gawk from the unix tools:
gawk -v sb="" "/Menu information:/,/===========/ { if ( $0 ~ /===========/ ) print sb; next } 1" input.txt >output.txt 

This should almost do what you need because in your output an extra line of "========" is missing if i understood properly : you wanted to remove the lines between one begining with "Menu information:" and one containing only "=====".

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy