![]() |
|
|
|||||||
| Petri.co.il is happy to award auglan the title of Most Valuable Member !!! |
| Register | Calendar |
Search |
Today's Posts |
Mark Forums Read |
| Notices |
|
|
.bat Find and replace textthis thread has 6 replies and has been viewed 3947 times
|
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||||||
|
||||||||
|
I have some files that contain some of if not all of the following:
Program RxBIN RXPCN RxGroup MemberID not all files will have all of those headers but the ones that do I will need to replace so it looks like this: @Program @RxBIN @RXPCN @RxGroup @MemberID Thanks in Advance, Joe |
|
#2
|
||||||||||
|
||||||||||
|
If it is a word document, you can write a macro to do it -- you do not have to use a bat file. if it is some other format, please give us a clue!
__________________
Tom Jones MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+ PhD, MSc, FIAP, MIITT IT Trainer / Consultant Ossian Ltd Scotland ** Remember to give credit where credit is due and leave reputation points where appropriate ** |
|
#3
|
||||||||
|
||||||||
|
Solved
I found the solution http://www.dostips.com/?t=Batch.FindAndReplace had to rewite it a bit to actually get the job done. I am sure there is an easier way of doing this but I got it to work call BatchSubstitute.bat Program @Program InDesignData.txt >newfile.txt Code:
if not exist newfile.txt goto skip del "InDesignData.txt" ren "newfile.txt" "InDesignData.txt" :skip call BatchSubstitute.bat RxBIN @RxBIN InDesignData.txt >newfile.txt if not exist newfile.txt goto skip del "InDesignData.txt" ren "newfile.txt" "InDesignData.txt" :skip call BatchSubstitute.bat RXPCN @RXPCN InDesignData.txt >newfile.txt if not exist newfile.txt goto skip del "InDesignData.txt" ren "newfile.txt" "InDesignData.txt" :skip call BatchSubstitute.bat RxGroup @RxGroup InDesignData.txt >newfile.txt if not exist newfile.txt goto skip del "InDesignData.txt" ren "newfile.txt" "InDesignData.txt" :skip call BatchSubstitute.bat MemberID @MemberID InDesignData.txt >newfile.txt if not exist newfile.txt goto skip del "InDesignData.txt" ren "newfile.txt" "InDesignData.txt" :skip Last edited by biggles77; 7th September 2010 at 15:58.. Reason: Wrap script in CODE tag |
|
#4
|
||||||||||
|
||||||||||
|
Thanks for posting back with your find.
__________________
"There I stood at the bar, wearing a Mae West, no jacket, and beginning to leak blood from my torn boot. None of the golfers took any notice of me - after all, I wasn't a member!" Kenneth Lee - after being shot down during the Battle of Britain on the 18th August 1940. ************************************************** ********************** ** Remember to give credit where credit is due and leave reputation points where appropriate ** ************************************************** ********************** |
|
#5
|
||||||||||
|
||||||||||
|
Names of the labels that are used in a batch must be unique. Your batch is using :skip multiple times and therefore the batch won't work as expected.
Further more, your batch will add an "@" also if there was already a leading @ added to the header text. A good command line utility for text processing that I would recommend is gnu sed for Windows (free for download)! But if you don't like to use tools (like sed or gawk) - you can try this "all in one batch" solution, Code:
@echo off & SETLOCAL ENABLEEXTENSIONS
Set "file=InDesignData.txt"
color 6A & echo please wait.. & title parsing file, "%file%"
call:BatchSubstitude "%file%" > "newfile.txt"
MOVE /Y "newfile.txt" "InDesignData.txt"
goto:EOF
:BatchSubstitude *** source http://www.dostips.com/?t=Batch.FindAndReplace
SETLOCAL DISABLEDELAYEDEXPANSION
for /f "tokens=1,* delims=]" %%A in ('"type "%~1"|find /n /v """') do (
set "line=%%B"
if defined line (
call:replace "Program" "@Program"
call:replace "RxBIN" "@RxBIN"
call:replace "RXPCN" "@RXPCN"
call:replace "RxGroup" "@RxGroup"
call:replace "MemberID" "@MemberID"
call set "line=echo.%%line%%"
for /f "delims=" %%* in ('"echo."%%line%%""') do (%%~*)
) ELSE (echo.))
ENDLOCAL
exit /b 0
:replace
>nul 2>&1 (
call set line |Findstr.exe /RIC:"\<%~1\>" && call set line |Findstr.exe /RIVC:"\<@%~1\>" && call set "line=%%line:%~1=%~2%%")
exit /b 0
\Rems
__________________
This posting is provided "AS IS" with no warranties, and confers no rights. __________________ ** Remember to give credit where credit's due ** and leave Reputation Points for meaningful posts |
|
#6
|
||||||||||
|
||||||||||
|
Might have to use this one
Thanks! |
|
#7
|
||||||||
|
||||||||
|
Here is a quick Powershell alternative (from Powershell.com iirc):
Quote:
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Search and Replace text via CMD? | rack04 | General Scripting | 6 | 24th June 2009 10:22 |
| Script that will extract text for a text file | rack04 | General Scripting | 12 | 30th May 2009 19:47 |
| Find and Replace within AD? | Tieem | Active Directory | 3 | 7th November 2008 12:35 |
| Windows text file parser; I need to compare two text files... how? | Nonapeptide | Misc | 10 | 30th April 2008 14:21 |
| XP does not find text in files. | JDMils | Windows 2000 Pro, XP Pro | 7 | 6th September 2006 14:27 |