Computing.Net > Forums > Windows XP > Removing '$' from a text file.

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.

Removing '$' from a text file.

Reply to Message Icon

Name: blink
Date: March 30, 2006 at 06:04:52 Pacific
OS: XP
CPU/Ram: P4/1GHZ
Product: Me!
Comment:

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 $.



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: March 30, 2006 at 15:16:32 Pacific
Reply:

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


0

Response Number 2
Name: blink
Date: March 30, 2006 at 22:41:48 Pacific
Reply:

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


0

Response Number 3
Name: dtech10
Date: March 31, 2006 at 06:18:17 Pacific
Reply:

Hi
This Help

echo 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



0

Response Number 4
Name: blink
Date: March 31, 2006 at 06:54:06 Pacific
Reply:

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?


0

Response Number 5
Name: dtech10
Date: March 31, 2006 at 07:59:04 Pacific
Reply:

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.



0

Related Posts

See More



Response Number 6
Name: blink
Date: April 11, 2006 at 01:50:16 Pacific
Reply:

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?


0

Response Number 7
Name: dtech10
Date: April 20, 2006 at 05:42:12 Pacific
Reply:

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
)



0

Sponsored Link
Ads by Google
Reply to Message Icon

Ms updates windows sockets initializ...



Post Locked

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


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: Removing '$' from a text file.

text line removal with a batch file www.computing.net/answers/windows-xp/text-line-removal-with-a-batch-file/153490.html

Batch File Parsing a text file www.computing.net/answers/windows-xp/batch-file-parsing-a-text-file-/151425.html

parsing through a text file using a batch www.computing.net/answers/windows-xp/parsing-through-a-text-file-using-a-batch-/180355.html