Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I've created a batch file that exports the samid for all computers in a certain AD group. This however, exports the samid+$ so 'hostname$' is what it looks like.
Now, I've tried filtering for $ using find /v "$" but this doesnt seem to work, probably cause $ also refers to a variable.
How do I make clear I want to filter on the character $ and not a string $.

Hi blink
Do you want only "$" removing or all lines that contain that charactor, which the find command will do.

I just want to remove the $ character. Find doesnt work, cause it seems to read the $ and expects a string.

Hi
This Helpecho off
setlocal enabledelayedexpansion
if "%1"=="" goto Usage
if not exist %1.txt goto Error
if "%2"=="" goto Usage
for /f "tokens=*" %%a in (%1.txt) do (
set Tmp=%%a
set Tmp=!Tmp:$=!
echo !Tmp! >> %2.txt
)
goto Quit
:Error
echo.
echo %1.txt File Not Found
echo.
:Usage
echo Text Files Assummed
echo If DestFile alReady exists it will appended
echo Usage: Test.bat SourceFile DestFile
:Quit
setlocal

Thanks, it does work yea heh. However, I want to implement this function into existing code. What part filters for the $ and how does it work?

Hi
This is the part that does the work.for /f "tokens=*" %%a in (%1.txt) do (
set Tmp=%%a
set Tmp=!Tmp:$=!
echo !Tmp! >> %2.txt
)%1.txt & %2.txt refers to the source and destination files from the command line.
The For Loop gets each line of text from the source file, this is stored in the %%a variable.
The Tmp varable stores this ie. set Tmp=%%a
The "set Tmp=!Tmp:S=!, sets all the "$" to ""
in other words deletes them.
The "Echo !Tmp! >> %2.txt", echo the changed data to the desination file.
The "setlocal enabledelayedexpansion" allows the set command to opererate in the For Loop corretly keeping it's changed data through the For Loop
The "SetLocal" at the end cleans up the used environment variables. Not strictly necessary.
Hope this helps I'm better at programming that explaining.

Right, I get how it works, well sorta that is heh. I'm still having trouble implementing it into my batch file though.
The data with the $'s in my batch file is put out by a type command. How do I connect this to that and have that output with type too?

Hi
Can't you just use "Type %2.txt"or
for /f "tokens=*" %%a in (%1.txt) do (
set Tmp=%%a
set Tmp=!Tmp:$=!
echo !Tmp!
echo !Tmp! >> %2.txt
)

![]() |
Ms updates
|
windows sockets initializ...
|

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