[help] i need to extract data from a text file via batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
cheeseng
Posts: 19
Joined: 30 May 2012 03:36

[help] i need to extract data from a text file via batch

#1 Post by cheeseng » 30 May 2012 03:40

i have a source file with many entry of the follow data
==============================================* *
* * * * * * * * *
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
====================================================================================================================================
XXXXXXXX |
XXXXXXXXX | --- other information not relevant
XXXXXXXXXX |
=====================================================================================================================================
* *
* * * * * * * * *
User information . . . . . : : User name . . . . . . . . . : ABCG * *
User text . . . . . . . . . : BarchiesiGiancarlo
Begin menu . . . . . . . . : *NONE
Group jobs . . . . . . . . : 15
End group jobs . . . . . . : *NO
Command line on menus . . . : *NO
Attention-key program . . . : *ACTIVE
Reference user . . . . . . : OPERATOR
====================================================================================================================================

XXXXXXXX |
XXXXXXXXX | --- other information not relevant
XXXXXXXXXX |


=====================================================================================================================================
* *
* * * * * * * * *
User information . . . . . : : User name . . . . . . . . . : ABEF * *
User text . . . . . . . . . : Fabio Besomi*
Begin menu . . . . . . . . : *NONE
Group jobs . . . . . . . . : 15
End group jobs . . . . . . : *NO
Command line on menus . . . : *NO
Attention-key program . . . : *ACTIVE
ference user . . . . . . : OPERATOR
====================================================================================================================================

I need to extract the data out and put into the a csv format.

the end result should be like following:


User name ,User text, Begin menu, Group jobs ,End group jobs,Command line on menus ,Attention-key ....

ABAX ,Beatrice Raffaele, *NONE, 15,NO,NO,ACTIVE....
ABCG, Barchiesi Giancarlo, *NONE,...............

so basically this is the intention..

@echo off>%temp%\input.txt
cls
setlocal enabledelayedexpansion

for /f "tokens=*" %%1 in (input.txt) do (
set inline=%%1& set inline=!inline:.=!
if not "!inline:~0,3!" equ "* *" (
if not "!inline:~0,3!" equ "===" (
echo !inline!>>%temp%\input.txt
)
)
)



i got into this and kinda of stuck...


thanks for helping!!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: [help] i need to extract data from a text file via batch

#2 Post by foxidrive » 30 May 2012 04:15

See if this is good enough. Input file is file.txt and output file is file2.txt

It could fail depending on the text that you thought wasn't relevant. :)

Code: Select all

@echo off
setlocal enabledelayedexpansion
del file2.txt 2>nul
set c=0
for /f "delims=" %%a in ('type "file.txt" ^|find ". . :"') do (
set "var=%%a"
set "var=!var:* : =!"
set "var=!var:* : =!"
set /p "=!var!,">>file2.txt <nul
set /a c+=1
if !c! EQU 8 (
echo.>>file2.txt
set c=0)
)

cheeseng
Posts: 19
Joined: 30 May 2012 03:36

Re: [help] i need to extract data from a text file via batch

#3 Post by cheeseng » 30 May 2012 04:35

hi foxidrive,

thanks for the quick response..
the code kinda of work 60% and i do modified a bit

@echo off
setlocal enabledelayedexpansion

del file2.txt 2>nul
echo User name,User text,Begin menu,Group jobs,End group jobs,Command ^
line on menus,Attention-key program,Reference user>newfile.csv

set c=0
for /f "delims=" %%a in ('type "text_1.txt" ^|find ". . :"') do (
set "var=%%a"
set "var=!var:* : =!"
set "var=!var:* : =!"
set /p "=!var!,">>newfile.csv <nul
set /a c+=1
if !c! EQU 8 (
echo.>>newfile.csv
set c=0)
)

however the desired output is not in proper format.. I think i need to clarified more on the input source..

(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
_____________________________________________________________________________________________________________________________________
43 System Activity (WRKSYSACT) *REFUSER *USE *NO *YES
44 System Status (WRKSYSSTS) *REFUSER *USE *NO *YES 28/05/12 12:41:19 34
45 User Jobs (WRKUSRJOB) *REFUSER *USE *NO *YES 1/03/12 22:09:03 1
46 WORK Subsystem Jobs(WRKSBSJOB) *REFUSER *USE *NO *YES
47 User Profiles (DSPUSRPRF) *REFUSER *USE *NO *YES 2/01/12 7:00:40 7
48 Media using BRM (WRKMEDBRM) *REFUSER *USE *NO *YES
49 Work with Job Queue(WRKJOBQ) *REFUSER *USE *NO *YES
50 DISPLAY *REFUSER *USE *NO *YES
51 Display Message Qu.(DSPMSG) *REFUSER *USE *NO *YES 12/05/12 3:57:15 250
52 *REFUSER *USE *NO *YES
53 Work with Sys.Value(WRKSYSVAL) *REFUSER *USE *NO *YES
54 Display Data Area (DSPDTAARA) *REFUSER *USE *NO *YES 8/01/12 17:58:18 2
55 Display Job Log (DSPJOBLOG) *REFUSER *USE *NO *YES 6/06/11 22:59:48 5
56 Display Log (DSPLOG) *REFUSER *USE *NO *YES 6/06/11 22:52:05 1
57 Display Library (DSPLIB) *REFUSER *USE *NO *YES 6/06/11 22:22:58 2
58 Display Program (DSPPGM) *REFUSER *USE *NO *YES
59 Start Backup BRM (STRBKUBRM) *REFUSER *USE *NO *YES
60 Change Data Area (CHGDTAARA) *REFUSER *USE *NO *YES
61 Open/Close Subsystem *REFUSER *USE *NO *YES
62 Start Subsystem (STRSBS) *REFUSER *USE *NO *YES 8/01/12 17:48:40 8
63 End Subsystem (ENDSBS) *REFUSER *USE *NO *YES 6/06/11 46:05 7
64 *REFUSER *USE *NO *YES
65 *REFUSER *USE *NO *YES
69 Operations on Libraries *REFUSER *USE *NO *YES
70 Create Library (CRTLIB) *REFUSER *USE *NO *YES
71 Edit Library List (EDTLIBL) *REFUSER *USE *NO *YES
72 Add Library List (ADDLIBLE) *REFUSER *USE *NO *YES
73 Change Library List(CHGLIBL) *REFUSER *USE *NO *YES
74 Transfer to Olympic(OLY PR N) *REFUSER *USE *NO *YES
79 MESSAGES *REFUSER *USE *NO *YES
80 Send Break Message (SNDBRKMSG) *REFUSER *USE *NO *YES
81 Send Message (SNDMSG) *REFUSER *USE *NO *YES
84 Daily Save on Lugano BRMS *REFUSER *USE *NO *YES
85 Operations with BRMS *REFUSER *USE *NO *YES 11/05/12 16:55 63
88 DSPLOGBRM *REFUSER *USE *NO *YES 12/05/12 3:57:19 209
90 Work with Media Library Status *REFUSER *USE *NO *YES
95 GO BRMS *REFUSER *USE *NO *YES
99 Operation with SAVE FILE *REFUSER *USE *NO *YES
100 Display Save file (DSPSAVF) *REFUSER *USE *NO *YES
101 Create Save File (CRTSAVF) *REFUSER *USE *NO *YES
102 Clear Save File (CLRSAVF) *REFUSER *USE *NO *YES
109 Other Commands *REFUSER *USE *NO *YES
110 Start PDM (STRPDM) *REFUSER *USE *NO *YES 11/05/12 23:34:43 9
111 Retrieve CLP (RTVCLSRC) *REFUSER *USE *NO *YES
114 Initalize DIFSBS *REFUSER *USE *NO *YES
115 Take QSYSOPR Msgq in Break *REFUSER *USE *NO *YES
116 Runqry *N operator/triggers *REFUSER *USE *NO *YES 14/05/12 6:53:56 1
(C) SRC Secure Solutions bv iMenu400 Authorised Options for User 28/05/12 15:39:36 Page 3
=====================================================================================================================================
Option Option User Ref.user Group Date Time Number
number text authority authority job Activated used used acesses
_____________________________________________________________________________________________________________________________________
117 Submit Job (SBMJOB) *REFUSER *USE *NO *YES 10/05/12 22:58:01 4
118 TCP/IP Connection Status *REFUSER *USE *NO *YES 7/06/11 3:41:27 9
119 *REFUSER *USE *NO *YES
120 GO EEPADM *REFUSER *USE *NO *YES
121 Menu Backup(Use with caution) *REFUSER *USE *NO *YES
122 Full Backup of end of month *REFUSER *USE *NO *YES 1/02/12 6:16:25 9
123 Copy Spooled File (CPYSPLF) *REFUSER *USE *NO *YES
124 *REFUSER *USE *NO *YES
125 Request Emergency Password EEP *REFUSER *USE *NO *YES 29/11/11 13:14:40 7
126 Change Password *REFUSER *USE *NO *YES 26/03/12 15:24:30 8
127 Start TCP server *REFUSER *USE *NO *YES
128 Work with TCP/IP Network Stat *REFUSER *USE *NO *YES
129 Call Mirage *REFUSER *USE *NO *YES 11/05/12 3:48:27 53
130 Generation PDF Olyweb SGPOLY *REFUSER *USE *NO *YES 11/05/12 4:03:18 50
135 *REFUSER *USE *NO *YES
140 Send Spool Files (SNDTCPSPLF) *REFUSER *USE *NO *YES
141 Create File (CRTPF) *REFUSER *USE *NO *YES
142 IPMON Monitoring *REFUSER *USE *NO *YES 10/05/12 21:25:41 12
143 *REFUSER *USE *NO *YES
145 Monthly maintenance BRMS *REFUSER *USE *NO *YES 8/01/12 21:00:52 1
146 *REFUSER *USE *NO *YES
150 PM Spool (PMSPO) *REFUSER *USE *NO *YES
152 WRKSPL *REFUSER *USE *NO *YES
155 *REFUSER *USE *NO *YES
160 Start HTTP server *REFUSER *USE *NO *YES 6/06/11 29:48 8
165 *REFUSER *USE *NO *YES
170 WRKLNK *REFUSER *USE *NO *YES 11/05/12 4:02:31 59
180 WRKAUTL *REFUSER *USE *NO *YES
185 WRKPRB *REFUSER *USE *NO *YES 11/05/12 23:39:32 19
195 Missing Subsystems (DIFSBS) *REFUSER *USE *NO *YES
200 Create Directory (CRTDIR) *REFUSER *USE *NO *YES
202 *REFUSER *USE *NO *YES
205 Check the Bloomberg file. *REFUSER *USE *NO *YES
207 *REFUSER *USE *NO *YES
210 WRKSIT *REFUSER *USE *NO *YES
220 *REFUSER *USE *NO *YES
300 *REFUSER *USE *NO *YES
333 TRANSFER TO @SYSTEMOPR *REFUSER *USE *NO *YES
400 *REFUSER *USE *NO *YES
950 PWRDWNSYS *REFUSER *USE *NO *YES 8/01/12 17:24:12 1
960 *REFUSER *USE *NO *YES
999 SIGNOFF *REFUSER *USE *NO *YES 14/05/12 5:08:39 174
(C) SRC Secure Solutions bv iMenu400 Authorised Options for User 28/05/12 15:39:36 Page 4
=====================================================================================================================================
* *
* * * * * * * * * User information . . . . . : User name . . . . . . . . . : ABCG * * * * * * * * *
* User text . . . . . . . . . : Barchiesi Giancarlo *
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 23/04/12 7:10:34 132
10 Work with Job Scheduler (BOD) *REFUSER *USE *NO *YES 1/05/12 20:08:38 106
11 Work with Job Scheduler (EOD) *REFUSER *USE *NO *YES 4/05/12 20:52:40 133
12 Check JS History *REFUSER *USE *NO *YES
13 WRKJOBSCDE *REFUSER *USE *NO *YES 9/10/11 18:00:27 3
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 5/02/12 16:08:21 10
30 Active Jobs (WRKACTJOB) *REFUSER *USE *NO *YES 4/05/12 15:06:14 334
31 MQSeries (WRKMQM) *REFUSER *USE *NO *YES 6/08/11 20:33:36 1
32 Configurat.status (WRKCFGSTS) *REFUSER *USE *NO *YES 12/03/12 10:24:11 7
33 Submitted Jobs (WRKSBMJOB) *REFUSER *USE *NO *YES
34 Object Locks (WRKOBJLCK) *REFUSER *USE *NO *YES
35 Work with Job (WRKJOB) *REFUSER *USE *NO *YES
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
39 *REFUSER *USE *NO *YES
40 Device Description (WRKDEVD) *REFUSER *USE *NO *YES
41 Work with Libraries(WRKLIB) *REFUSER *USE *NO *YES
42 With Subsystems (WRKSBS) *REFUSER *USE *NO *YES 5/02/12 16:09:13 22
(C) SRC Secure Solutions bv iMenu400 Authorised Options for User 28/05/12 15:39:36 Page 5
=====================================================================================================================================
Option Option User Ref.user Group Date Time Number
number text authority authority job Activated used used acesses
_____________________________________________________________________________________________________________________________________
43 System Activity (WRKSYSACT) *REFUSER *USE *NO *YES
44 System Status (WRKSYSSTS) *REFUSER *USE *NO *YES 5/02/12 16:22:07 4
45 User Jobs (WRKUSRJOB) *REFUSER *USE *NO *YES 27/06/11 3:46:20 1
46 WORK Subsystem Jobs(WRKSBSJOB) *REFUSER *USE *NO *YES
47 User Profiles (DSPUSRPRF) *REFUSER *USE *NO *YES
48 Media using BRM (WRKMEDBRM) *REFUSER *USE *NO *YES 4/08/11 21:03:36 9
49 Work with Job Queue(WRKJOBQ) *REFUSER *USE *NO *YES
50 DISPLAY *REFUSER *USE *NO *YES
51 Display Message Qu.(DSPMSG) *REFUSER *USE *NO *YES 5/02/12 12:28:52 10
52 *REFUSER *USE *NO *YES
53 Work with Sys.Value(WRKSYSVAL) *REFUSER *USE *NO *YES
54 Display Data Area (DSPDTAARA) *REFUSER *USE *NO *YES
55 Display Job Log (DSPJOBLOG) *REFUSER *USE *NO *YES 5/02/12 15:41:31 10
56 Display Log (DSPLOG) *REFUSER *USE *NO *YES 2/08/11 21:03:55 3
57 Display Library (DSPLIB) *REFUSER *USE *NO *YES
58 Display Program (DSPPGM) *REFUSER *USE *NO *YES
59 Start Backup BRM (STRBKUBRM) *REFUSER *USE *NO *YES
60 Change Data Area (CHGDTAARA) *REFUSER *USE *NO *YES
61 Open/Close Subsystem *REFUSER *USE *NO *YES
62 Start Subsystem (STRSBS) *REFUSER *USE *NO *YES 5/02/12 16:08:47 13
63 End Subsystem (ENDSBS) *REFUSER *USE *NO *YES 2/09/11 2:23:18 9
64 *REFUSER *USE *NO *YES
65 *REFUSER *USE *NO *YES
69 Operations on Libraries *REFUSER *USE *NO *YES
70 Create Library (CRTLIB) *REFUSER *USE *NO *YES
71 Edit Library List (EDTLIBL) *REFUSER *USE *NO *YES
72 Add Library List (ADDLIBLE) *REFUSER *USE *NO *YES
73 Change Library List(CHGLIBL) *REFUSER *USE *NO *YES
74 Transfer to Olympic(OLY PR N) *REFUSER *USE *NO *YES
79 MESSAGES *REFUSER *USE *NO *YES
80 Send Break Message (SNDBRKMSG) *REFUSER *USE *NO *YES
81 Send Message (SNDMSG) *REFUSER *USE *NO *YES
84 Daily Save on Lugano BRMS *REFUSER *USE *NO *YES
85 Operations with BRMS *REFUSER *USE *NO *YES 21/04/12 53:27 61
88 DSPLOGBRM *REFUSER *USE *NO *YES 9/03/12 40:08 15
90 Work with Media Library Status *REFUSER *USE *NO *YES
95 GO BRMS *REFUSER *USE *NO *YES
99 Operation with SAVE FILE *REFUSER *USE *NO *YES
100 Display Save file (DSPSAVF) *REFUSER *USE *NO *YES
101 Create Save File (CRTSAVF) *REFUSER *USE *NO *YES
102 Clear Save File (CLRSAVF) *REFUSER *USE *NO *YES
109 Other Commands *REFUSER *USE *NO *YES
110 Start PDM (STRPDM) *REFUSER *USE *NO *YES
111 Retrieve CLP (RTVCLSRC) *REFUSER *USE *NO *YES
114 Initalize DIFSBS *REFUSER *USE *NO *YES
115 Take QSYSOPR Msgq in Break *REFUSER *USE *NO *YES
116 Runqry *N operator/triggers *REFUSER *USE *NO *YES
(C) SRC Secure Solutions bv iMenu400 Authorised Options for User 28/05/12 15:39:36 Page 6
=====================================================================================================================================
Option Option User Ref.user Group Date Time Number
number text authority authority job Activated used used acesses
_____________________________________________________________________________________________________________________________________
117 Submit Job (SBMJOB) *REFUSER *USE *NO *YES
118 TCP/IP Connection Status *REFUSER *USE *NO *YES 28/03/12 22:25:04 1
119 *REFUSER *USE *NO *YES
120 GO EEPADM *REFUSER *USE *NO *YES
121 Menu Backup(Use with caution) *REFUSER *USE *NO *YES
122 Full Backup of end of month *REFUSER *USE *NO *YES 5/02/12 12:31:42 17
123 Copy Spooled File (CPYSPLF) *REFUSER *USE *NO *YES
124 *REFUSER *USE *NO *YES
125 Request Emergency Password EEP *REFUSER *USE *NO *YES 7/02/12 21:47:05 5
126 Change Password *REFUSER *USE *NO *YES 3/04/11 11:57:29 1
127 Start TCP server *REFUSER *USE *NO *YES
128 Work with TCP/IP Network Stat *REFUSER *USE *NO *YES
129 Call Mirage *REFUSER *USE *NO *YES 23/04/12 5:59:46 54
130 Generation PDF Olyweb SGPOLY *REFUSER *USE *NO *YES 23/04/12 6:18:55 53
135 *REFUSER *USE *NO *YES
140 Send Spool Files (SNDTCPSPLF) *REFUSER *USE *NO *YES
141 Create File (CRTPF) *REFUSER *USE *NO *YES
142 IPMON Monitoring *REFUSER *USE *NO *YES 30/04/12 19:26:51 5
143 *REFUSER *USE *NO *YES
145 Monthly maintenance BRMS *REFUSER *USE *NO *YES 5/02/12 18:17:59 4
146 *REFUSER *USE *NO *YES
150 PM Spool (PMSPO) *REFUSER *USE *NO *YES
152 WRKSPL *REFUSER *USE *NO *YES
155 *REFUSER *USE *NO *YES
160 Start HTTP server *REFUSER *USE *NO *YES 1/09/11 23:26:42 6
165 *REFUSER *USE *NO *YES
170 WRKLNK *REFUSER *USE *NO *YES 23/04/12 6:18:29 68
180 WRKAUTL *REFUSER *USE *NO *YES
185 WRKPRB *REFUSER *USE *NO *YES 5/02/12 19:34:04 7
195 Missing Subsystems (DIFSBS) *REFUSER *USE *NO *YES
200 Create Directory (CRTDIR) *REFUSER *USE *NO *YES
202 *REFUSER *USE *NO *YES
205 Check the Bloomberg file. *REFUSER *USE *NO *YES
207 *REFUSER *USE *NO *YES
210 WRKSIT *REFUSER *USE *NO *YES
220 *REFUSER *USE *NO *YES
300 *REFUSER *USE *NO *YES
333 TRANSFER TO @SYSTEMOPR *REFUSER *USE *NO *YES
400 *REFUSER *USE *NO *YES
950 PWRDWNSYS *REFUSER *USE *NO *YES 5/02/12 15:41:59 7
960 *REFUSER *USE *NO *YES
999 SIGNOFF *REFUSER *USE *NO *YES 4/05/12 21:17:12 90
(C) SRC Secure Solutions bv iMenu400 Authorised Options for User 28/05/12 15:39:36 Page 7
=====================================================================================================================================
* *
* * * * * * * * * User information . . . . . : User name . . . . . . . . . : ABEF * * * * * * * * *
* User text . . . . . . . . . : Fabio Besomi - IBM System Engineer *
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

cheeseng
Posts: 19
Joined: 30 May 2012 03:36

Re: [help] i need to extract data from a text file via batch

#4 Post by cheeseng » 30 May 2012 04:37

and turn out my output is like that..

User name,User text,Begin menu,Group jobs,End group jobs,Command line on menus,Attention-key program,Reference user
ABAX * * * * * * * * *,Beatrice Raffaele *,*NONE, 15,*NO,*NO,*ACTIVE,OPERATOR,
ITOP,ITOP menu for the IBM operators,*REFUSER,ABCG * * * * * * * * *,Barchiesi Giancarlo *,*NONE, 15,*NO,
*NO,*ACTIVE,OPERATOR,ITOP,ITOP menu for the IBM operators,*REFUSER,ABEF * * * * * * * * *,Fabio Besomi - IBM System Engineer *,
*NONE, 15,*NO,*NO,*ACTIVE,OPERATOR,ITOP,ITOP menu for the IBM operators,
*REFUSER,ABTQ * * * * * * * * *,GIULIA BERTON *,*NONE, 15,*NO,*NO,*ACTIVE,
OPERATOR,ITOP,ITOP menu for the IBM operators,*REFUSER,ACAG * * * * * * * * *,Cavalli Graziano *,*NONE, 15,
*NO,*NO,*ACTIVE,OPERATOR,ITOP,ITOP menu for the IBM operators,*REFUSER,ACEA * * * * * * * * *,
Carretta Mauro *,*NONE, 15,*NO,*NO,*ACTIVE,OPERATOR,

how to igore all the ********* ?

thanks

cheeseng
Posts: 19
Joined: 30 May 2012 03:36

Re: [help] i need to extract data from a text file via batch

#5 Post by cheeseng » 30 May 2012 04:50

hi foxidrive,

User name,User text,Begin menu,Group jobs,End group jobs,Command line on menus,Attention-key program,Reference user
ABAX,Beatrice Raffaele*,*NONE, 15,*NO,*NO,*ACTIVE,OPERATOR
ABCG,Barchiesi Giancarlo *,*NONE, 15,*NO,*NO,*ACTIVE,OPERATOR
ABTQ,GIULIA BERTON,*NONE, 15,*NO,*NO,*ACTIVE,OPERATOR
ACAG,Cavalli Graziano,*NONE, 15,*NO,*NO,*ACTIVE,OPERATOR

this is the desired outcome :) hope to help u look into it...
total has 8 column header...

then has tonnes of input..

In fact, when i investigate the code i realize the code u gave me use find ". . :"' which is good just that.. i have other data which also has such identity which i might not want in my output... so beside that what else can use?

thanks.. your effort is much appreciated.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: [help] i need to extract data from a text file via batch

#6 Post by Aacini » 30 May 2012 05:11

This Batch file was developed in accordance with your first request:

EDIT: This Batch file have the modifications requested in posterior posts:

Code: Select all

@echo off
setlocal EnableDelayedExpansion
set numFields=8
call :processHeader < sourceFile.txt >  outputFile.csv
call :processRecord < sourceFile.txt >> outputFile.csv
goto :EOF

:processHeader
set /P line=
if "!line:~18,16!" neq "User information" goto processHeader
for /F "tokens=2 delims=:" %%a in ("!line!") do (
   set header=%%a
)
set header=!header: .=!
set header=!header:~1,-1!
for /L %%i in (2,1,%numFields%) do (
   set /P line=
   for /F "tokens=1 delims=." %%a in ("!line!") do (
      set token=%%a
   )
   if %%i equ 2 set token=!token:~2!
   set "header=!header!,!token:~0,-1!"
)
echo !header!
exit /B

:processRecord
set line=
set /P line=
if not defined line exit /B
if "!line:~18,16!" neq "User information" goto processRecord
for /F "tokens=3 delims=:" %%a in ("!line!") do (
   set record=%%a
)
set record=!record: *=!
set record=!record:~1!
for /L %%i in (2,1,%numFields%) do (
   set /P line=
   for /F "tokens=2 delims=:" %%a in ("!line!") do (
      set token=%%a
   )
   set "record=!record!,!token:~1!"
)
echo !record!
goto processRecord

Output result with your first example data:
Result wrote:User name,User text,Begin menu,Group jobs,End group jobs,Command line on menus,Attention-key program,Reference user
ABAX * *, Beatrice Raffaele *, *NONE, 15, *NO, *NO, *ACTIVE, OPERATOR
ABCG * *, BarchiesiGiancarlo , *NONE, 15, *NO, *NO, *ACTIVE, OPERATOR
ABEF * *, Fabio Besomi*, *NONE, 15, *NO, *NO, *ACTIVE, OPERATOR
Last edited by Aacini on 30 May 2012 16:00, edited 1 time in total.

cheeseng
Posts: 19
Joined: 30 May 2012 03:36

Re: [help] i need to extract data from a text file via batch

#7 Post by cheeseng » 30 May 2012 05:33

hi Aacini,

thanks for the help.. the code work for first part..
But when u look on my actual source file after that it seems doesn't has data in the output..

hhmm...
so could you assist me on this..
thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: [help] i need to extract data from a text file via batch

#8 Post by foxidrive » 30 May 2012 05:58

This relies heavily on the format of your input file - as batch file often do when parsing files. See how it goes.

Code: Select all

@echo off
setlocal enabledelayedexpansion
del file2.txt 2>nul
set c=0
for /f "delims=" %%a in (
'type "file.txt" ^|find ". . :"^|find /v /i "Menu information:"^|find /v /i "Menu text . . . . . . . . . :"^|find /v /i "Reference user authority . :"^|find /v /i "User authority . . . . . . :"') do (
set "var=%%a"
set "var=!var:* : =!"
set "var=!var:* : =!"
set "var=!var: * * * * * * * * *=!"
set /p "=!var!,">>file2.txt <nul
set /a c+=1
if !c! EQU 8 (
echo.>>file2.txt
set c=0)
)

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: [help] i need to extract data from a text file via batch

#9 Post by Aacini » 30 May 2012 16:18

I modified the program above (in my first post) to meet your additional modifications. This is the result when run with your very large source file:

Result wrote:User name,User text,Begin menu,Group jobs,End group jobs,Command line on menus,Attention-key program,Reference user
ABAX,Beatrice Raffaele *,*NONE,15,*NO,*NO,*ACTIVE,OPERATOR
ABCG,Barchiesi Giancarlo *,*NONE,15,*NO,*NO,*ACTIVE,OPERATOR
ABEF,Fabio Besomi - IBM System Engineer *,*NONE,15,*NO,*NO,*ACTIVE,OPERATOR

Note that this result is not the same of your previous sample of the output you want. :? This makes me to review the whole source data searching for the error in my program: there was no error in my program, but in your example :!:

I suggest you to pay more attention in future topics: post the real data and precise output samples, please! :evil:

Antonio

cheeseng
Posts: 19
Joined: 30 May 2012 03:36

Re: [help] i need to extract data from a text file via batch

#10 Post by cheeseng » 30 May 2012 20:29

hi people, thanks for the help.. really appreciate :P :P
as i cant attached a files here.. and copy and paste the source data will affect the format...
hence i decided to do a print screen and put over here...

I will share a fews link to showcase the inputs
inputs


1
http://www.flickr.com/photos/79704604@N03/7305701700/

2
http://www.flickr.com/photos/79704604@N03/7305702180/

Hope this time will be clearer..
Dear aacini,

for the processheader part, how about use this code?
echo User name,User text,Begin menu,Group jobs,End group jobs,Command ^ ine on menus,Attention-key program,Reference user, Group I, Group I Description,Group II, Group II Description,Group III, Group III Description, Group IV, Group IV Description,Group V, Group V Description,Group VI, Group VI Description>outputfile.csv

If refer to the first print-screen (1) that is the most basic output and i guess you have help me achieve and thanks alot..

for
case (2) when reference user is multiple it means there has group.
my boss want me to include their group which is the keyword 'GRP'.... ,security info..

so i thought whether can use grp as keyword to search for every entry that has 'grp' attend the 2 column to the group(no) , group(no) description??

@foxidrive,

thanks you for your help too~ however, i think is my fault not provide the source file accurately...
i will provide the desired output on next post!!! sorry for any misunderstood in the previous post.. do let me know if you are not clear


Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: [help] i need to extract data from a text file via batch

#12 Post by Squashman » 30 May 2012 21:16

cheeseng wrote:copy and paste the source data will affect the format...
hence i decided to do a print screen

That is what the code tags are for!

Hope this time will be clearer..

Let's hope so for your sake. I see you have this posted on multiple forums on the Internet and a few of them are frustrated with your lack of detail.

cheeseng
Posts: 19
Joined: 30 May 2012 03:36

Re: [help] i need to extract data from a text file via batch

#13 Post by cheeseng » 30 May 2012 21:42

HI Squashman,

I am sorry and sincerely apologize as my boss didn't gave me a full picture at first :(

I hope the print screen will work for those who help me!!!..

As i am a beginner to tech forum.. I will definitely be more careful in the future post ... :roll:
Hope you guys dun mind...

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: [help] i need to extract data from a text file via batch

#14 Post by foxidrive » 30 May 2012 23:20

Posting in multiple places is pretty rude, isn't it guys?
You get people to do your work *and* more than one set of collaborators are working on the same task...

Somehow I doubt anyone here will bother any further - and I have no idea how screenshots are going to help in testing code...

cheeseng
Posts: 19
Joined: 30 May 2012 03:36

Re: [help] i need to extract data from a text file via batch

#15 Post by cheeseng » 30 May 2012 23:28

sorry foxidrive,

it is really my first time doing such task and i am not aware such thing will trouble u guys so much..
However, i dunno which way i can share the source data and desired output in a better way..
Plz enlighten me, so that in future request i will really ensure the source data is accurate

Post Reply