Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsWindows Server 2003Windows 2000Windows NTSmall Business ServerVirtual ServerExchange ServerIISHost Integration ServerISA ServerSMSWSUSMOMWindows Media ServerSecurityCertification
Related Topics
SQL ServerMS WindowsMS OfficePC HardwareMore Topics ...

Windows Server Forum / Windows NT / Applications / May 2004

Tip: Looking for answers? Try searching our database.

batch file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rcmathen@hotmail.com - 11 May 2004 22:32 GMT
Need to search a txt file.  I have several txt srings as
follows.

aeb010
ceb010
aec030
cec030
lap030
pal010

I would like the output to read
aeb010 ceb010
aec030 cec030
lap030
pal010

please help
Phil Robyn [MVP] - 11 May 2004 23:22 GMT
> Need to search a txt file.  I have several txt srings as
> follows.
[quoted text clipped - 13 lines]
>
> please help

- - - - - - - - - - begin screen capture Win2000 - - - - - - - - - -
C:\cmd>type %temp%\SomeText.file
aeb010
ceb010
aec030
cec030
lap030
pal010

C:\cmd>demo\batchfile
line1=aeb010 ceb010
line2=aec030 cec030
line3=lap030
line4=pal010

C:\cmd>rlist demo\batchfile.cmd
=====begin C:\cmd\demo\batchfile.cmd ====================
01. @echo off
02. setlocal enabledelayedexpansion
03. set /a counter = 0, number = 0
04. for /f "tokens=*" %%a in (c:\temp\SomeText.file) do call :main %%a
05. set line
06. goto :EOF
07. :main
08. set /a counter += 1
09. echo .2.4. | findstr /c:".%counter%." > nul
10. if %errorlevel% gtr 0 (
11.    set /a number += 1
12.    set line!number!=%*
13. ) else (
14.    call set line%number%=%%line%number%%% %*
15. )
=====end   C:\cmd\demo\batchfile.cmd ====================
- - - - - - - - - - end   screen capture Win2000 - - - - - - - - - -

Signature

Phil Robyn
Univ. of California, Berkeley

u n z i p   m y   a d d r e s s   t o   s e n d   e - m a i l

anonymous@discussions.microsoft.com - 12 May 2004 14:56 GMT
I am running NT.  Does that make a difference?  I can not
seem to get this to run correctly.  Does it matter if the
input is as follows?

aeb010
lap030
lap050
aec010
ceb010
cec010

>-----Original Message-----
>
[quoted text clipped - 17 lines]
>
>- - - - - - - - - - begin screen capture Win2000 - - - - -
- - - - -
>C:\cmd>type %temp%\SomeText.file
>aeb010
[quoted text clipped - 29 lines]
>=====end   C:\cmd\demo\batchfile.cmd ====================
>- - - - - - - - - - end   screen capture Win2000 - - - - -
- - - - -
Phil Robyn [MVP] - 12 May 2004 18:25 GMT
> I am running NT.  Does that make a difference?  I can not
> seem to get this to run correctly.  Does it matter if the
[quoted text clipped - 6 lines]
> ceb010
> cec010

No, it doesn't matter what the input is.  NT4.0 does not support
'enabledelayedexpansion', which is probably why the previous
version doesn't work.  (Also, the comparison operators [specifically,
'gtr'] must be in upper case in NT4.0.)  The following should work in
NT4.0 (but I tested it only in Win2000 as I don't currently have access
to an NT4.0 machine):

- - - - - - - - - - begin screen capture Win2000 - - - - - - - - - -
C:\cmd>demo\batchfileNT
line1=aeb010 lap030
line2=lap050 aec010
line3=ceb010
line4=cec010

C:\cmd>rlist demo\batchfileNT.cmd
=====begin C:\cmd\demo\batchfileNT.cmd ====================
01. @echo off
02. setlocal
03. set /a counter = 0, number = 0
04. for /f "tokens=*" %%a in (c:\temp\SomeText.file) do call :main %%a
05. set line
06. goto :EOF
07.
08. :main
09. set rec=%*
10. set /a counter += 1
11. echo .2.4. | findstr /c:".%counter%." > nul
12. if %errorlevel% GTR 0 (
13.    call :newline
14. ) else (
15.    call set line%number%=%%line%number%%% %rec%
16. )
17. goto :EOF
18.
19. :newline
20. set /a number += 1
21. set line%number%=%rec%
22. goto :EOF
=====end   C:\cmd\demo\batchfileNT.cmd ====================
- - - - - - - - - - end   screen capture Win2000 - - - - - - - - - -

>>-----Original Message-----
>>
[quoted text clipped - 65 lines]
>
>>.

Signature

Phil Robyn
Univ. of California, Berkeley

u n z i p   m y   a d d r e s s   t o   s e n d   e - m a i l

anonymous@discussions.microsoft.com - 12 May 2004 18:48 GMT
I have complety mis led.

I have a text file like the following. The output is
futher down.  Need the "A" and "C" (ex:AAA010 and CAA010)
alike entries on the same line.

(INPUT)
AAA010
AAK040
LAP030
AEB020
AEC030
AAL030
ABH080
AAL020
CEB020
CEC030
CAK040
CAL020
LFA000
CBH135
CEA010
CEA040
LAP050
LAQ040
LAL015
PAA010
PAK060
PAL015
PAQ119
PBH070
PBI040
PZD040
PZD045
CAL030
CBH080
LAP010
ABH135
AEA010
AEA040
AEB010
CEB010
CAA010
LBH030
LBH140
LBH210
LBI020
LDB090

(output)
AAA010 CAA010
AAK040 CAK040
AAL020 CAL020
AAL030 CAL030
ABH080 CBH080
ABH135 CBH135
AEA010 CEA010
AEA040 CEA040
AEB010 CEB010
AEB020 CEB020
AEC030 CEC030
LAL015
LAP010
LAP030
LAP050
LAQ040
LBH030
LBH140
LBH210
LBI020
LDB090
LFA000
PAA010
PAK060
PAL015
PAQ119
PBH070
PBI040
PZD040
PZD045
Phil Robyn [MVP] - 12 May 2004 22:02 GMT
> I have complety mis led.
>
[quoted text clipped - 76 lines]
> PZD040
> PZD045

Yes, you have 'complety mis led.'  Here is my *last* response to you in this thread.
The idea is not that you are to ask for and receive a turnkey solution to some ill-
defined problem; rather, by studying the example solutions provided, you will learn
how to better define your problems and, more importantly, be able to learn how to
create your own solutions.

- - - - - - - - - - begin screen capture Win2000 - - - - - - - - - -
C:\cmd>demo\batchfileNTv2
line1.=AAA010 CAA010
line2.=AAK040 CAK040
line3.=AAL020 CAL020
line4.=AAL030 CAL030
line5.=ABH080 CBH080
line6.=ABH135 CBH135
line7.=AEA010 CEA010
line8.=AEA040 CEA040
line9.=AEB010 CEB010
line10.=AEB020 CEB020
line11.=AEC030 CEC030
line12.=LAL015
line13.=LAP010
line14.=LAP030
line15.=LAP050
line16.=LAQ040
line17.=LBH030
line18.=LBH140
line19.=LBH210
line20.=LBI020
line21.=LDB090
line22.=LFA000
line23.=PAA010
line24.=PAK060
line25.=PAL015
line26.=PAQ119
line27.=PBH070
line28.=PBI040
line29.=PZD040
line30.=PZD045

C:\cmd>rlist demo\batchfileNTv2.cmd
=====begin C:\cmd\demo\batchfileNTv2.cmd ====================
01. @echo off
02. setlocal
03. sort c:\temp\SomeFile.txt > c:\temp\SomeFile.sorted
04. set /a number = 0
05. for /f "tokens=*" %%a in (
06.   'findstr /b /i "a" c:\temp\SomeFile.sorted'
07. ) do call :concat %%a
08. call :remainder
09. for /l %%a in (1,1,%number%) do set line%%a.
10. goto :EOF
11. :concat
12. set item=%*
13. set srch=%item:~1%
14. set /a number += 1
15. for /f "tokens=*" %%b in (
16.   'findstr /b /i "c%srch%" c:\temp\SomeFile.sorted'
17. ) do set line%number%.=%item% %%b
18. goto :EOF
19. :remainder
20. for /f "tokens=*" %%c in (
21.   'findstr /b /r "[^A-C]" c:\temp\SomeFile.sorted'
22. ) do call :addline %%c
23. goto :EOF
24. :addline
25. set /a number += 1
26. set line%number%.=%*
27. goto :EOF
=====end   C:\cmd\demo\batchfileNTv2.cmd ====================
- - - - - - - - - - end   screen capture Win2000 - - - - - - - - - -

Signature

Phil Robyn
Univ. of California, Berkeley

u n z i p   m y   a d d r e s s   t o   s e n d   e - m a i l

Robert C. Matheny - 13 May 2004 14:16 GMT
Phil

I have used what you have given and modified it for four
other scripts I use.  I am just now getting into writing
programs and finding it a challenge.  Sorry for all the
confusion.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.