Computing.Net > Forums > Programming > Find and replace on multiple lines

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.

Find and replace on multiple lines

Reply to Message Icon

Name: CrazyEd
Date: November 28, 2008 at 07:05:28 Pacific
OS: Winn NT
CPU/Ram: Intel/1.5G
Comment:

I found the following code on this form to allow me to strip trailing spaces from rows in a file. Unfortunately it only seems to process the first row.

Can anyone provide any insight into what I need to modify to loop through a file and strip trailing spaces on every row.?

Sample Code
--------------------------
@Echo Off
SetLocal EnableDelayedExpansion
For %%J in (desknet_FA_list_teams.txt) Do (
For /F "tokens=* delims=" %%A in (%%J) Do (
Set Row=%%A
If not "!Row:~0,1!"=="#" (
:LOOP
If "!Row:~-1,1!"==" " (
(Set Row=!Row:~0,-1!) & GoTo :LOOP)
Set Row=!Row:tiplespawn 0=tiplespawn 1!
Echo !Row!>> %%~cleanFAList.txt)))



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: November 28, 2008 at 09:43:30 Pacific
Reply:

============================================================
:: get out trailing spaces

@echo off & setLocal EnableDelayedExpansion > newfile

for /f "tokens=* delims= " %%a in (myfile) do (
set str=%%a
call :sub1
)

goto :eof

:sub1
:loop
if "!str:~-1!"==" " set str=!str:~0,-1!& goto :loop
echo !str!>> newfile
goto :eof


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

M2


0
Reply to Message Icon

Related Posts

See More







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: Find and replace on multiple lines

CMD script find and replace text www.computing.net/answers/programming/cmd-script-find-and-replace-text/15412.html

Find and Replace text in Batch File www.computing.net/answers/programming/find-and-replace-text-in-batch-file/12413.html

Batch find and replace www.computing.net/answers/programming/batch-find-and-replace/15145.html