Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

how to use batch file to extract lines from text file

- - - - -

  • Please log in to reply
3 replies to this topic

#1
jasonchia

jasonchia
  • Member
  • 1 posts
  • Joined 31-May 12
  • OS:XP Home
  • Country: Country Flag
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


How to remove advertisement from MSFN

#2
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,654 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

So, any way to extract the required data..

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

jaclaz

#3
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,799 posts
  • Joined 12-May 07
  • OS:none specified
  • Country: Country Flag
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

Posted Image


#4
allen2

allen2

    Not really Newbie

  • Member
  • PipPipPipPipPipPipPip
  • 1,814 posts
  • Joined 13-January 06
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 "=====".




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users