Computing.Net > Forums > Programming > Parsing text in a batch

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Parsing text in a batch

Reply to Message Icon

Name: masimar
Date: April 24, 2006 at 18:03:09 Pacific
OS: NA
CPU/Ram: NA
Comment:

I'm not sure if this is a parsing problem or not, but I would appreciate help. My fingers are bleeding from goolgle searches on the problem.
I'm trying to list processes with full path in windows xp home and pro. Pv.exe does give the full path, but with spaces. I used tokens=1, etc. and can list all of the process paths, no matter how many spaces in the path.
C:\Program Files\Symantec\Norton Ghost\Agent\PQV2iSvc.exe
However, to actually use the path to process files, I have to put quotes around them. so I tried (list from filepath.txt):
for /f "tokens=1,2 delims=" %%a in (filepath.txt) do echo "%%a">>path.txt
and I get:
"C:\Program Files\Symantec\Norton Ghost\Agent\PQV2iSvc.exe "

The spaces after .exe are not all in the same place, but there are spaces after every exe. I don't know how to get rid of them. Can someone help?


Mark



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: April 25, 2006 at 01:05:13 Pacific
Reply:

Take a look at this bat. If we're on the right track, we can hammer out the rest.

::== nospace.bat
@echo off

echo C:\Program Files\Symantec\Norton Ghost\Agent\PQV2iSvc.exe > filepath.txt

for /f "tokens=*" %%a in (filepath.txt) do echo %%a
for /f "tokens=*" %%a in (filepath.txt) do call :sub1 %%a
goto :eof

:sub1

echo %1%2%3%4%5%6%7%8%9 > nospace.txt
goto :eof
:: DONE


=====================================
If at first you don't succeed, you're about average.

M2Go



0

Response Number 2
Name: masimar
Date: April 25, 2006 at 06:05:55 Pacific
Reply:

I appreciate the response. Your solution works great on paths with no spaces except the ones at the end, but for directories like \Norton Ghost\ or \Program Files\, the spaces need to be there for the path to be valid. Since what I want to do process the file at the end of the path - no matter what is it -, I don't see how this could work considering all the possible variables. Any ideas?

Mark


0

Response Number 3
Name: IVO
Date: April 25, 2006 at 06:55:39 Pacific
Reply:

The following slightly modified code from the native M2's one achieves what you wish

@Echo Off

For /f "tokens=* delims=" %%a in (filepath.txt) Do Call :NORM %%a
GoTo :EOF

:NORM
Echo "%*" >> Path.txt
GoTo :EOF

where Call :NORM %%a fits the line starting with For (no CR/LF between).


0

Response Number 4
Name: Mechanix2Go
Date: April 25, 2006 at 07:01:07 Pacific
Reply:

Thanks, IVO


=====================================
If at first you don't succeed, you're about average.

M2Go



0

Response Number 5
Name: masimar
Date: April 25, 2006 at 07:08:21 Pacific
Reply:

Beautiful. I thank both of you. I'm never motivated to learn anything until I need it. I
appreciate your knowledge.

Mark


0

Related Posts

See More



Response Number 6
Name: UselessLifeform
Date: May 14, 2006 at 17:25:13 Pacific
Reply:

Ok I have a slightly different and probably A-LOT-easier-to-solve problem. I'm trying to extract JUST the PID (process ID) from a .txt file who's output comes from pslist.exe. Keep in mind I know close to zero about batch files and ANY general programming/script writing!

pslist.exe > list.txt
next I use FIND "ctfmon" list.txt >listp.txt

The result is a line that looks like this:

---------- LIST.TXT
ctfmon 4016 8 1 67 1012 0:00:00.100 0:15:21.394

ALL I WANT is that PID (4016) clean and pure, so I can store it a variable for later use by another program. Any ideas? I'm sure this complex crap i'm tearing the a$$ out of myself to do can be done like in one line. I know I suck but hey, thats life.


0

Response Number 7
Name: Mechanix2Go
Date: May 14, 2006 at 18:17:36 Pacific
Reply:

Try this:

for /f "tokens=2" %%T in (list.txt) do set myvar=%%T


If at first you don't succeed, you're about average.

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Parsing text in a batch

Extract comp. alias in a batch file www.computing.net/answers/programming/extract-comp-alias-in-a-batch-file/11253.html

Piping text within a batch file www.computing.net/answers/programming/piping-text-within-a-batch-file/11068.html

Cut few text in a matched line www.computing.net/answers/programming/cut-few-text-in-a-matched-line/18620.html