Remove @ and $ from the File

Microsoft Windows xp professional sp2c e...
July 11, 2010 at 22:03:28
Specs: Windows 2003 or 2008
Dear Experts,

I am working on Windows 2003. I want a batch file which can:

Open a file in D:/Test directory and remove all the @ and $. And save the file the file with out changing the name.

Thanks In Advance,
Phani Akella.

Thanks,
Phani Akella


See More: Remove @ and $ from the File

Report •


#1
July 12, 2010 at 00:24:21
if you can download stuff, you can use sed for windows. Then this one liner will do the job

sed "s/[@$]//g" file

GNU win32 packages | Gawk


Report •

#2
July 12, 2010 at 00:56:18
Hi,

Can we do this with out sed? If possible please let me know how we can do this with normal batch file.

Thanks,
Phani Akella


Report •

#3
July 12, 2010 at 14:21:47
forget sed

=============================

@echo off > newfile & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in (myfile) do (
set S=%%a
set S=!S:@=!
set S=!S:$=!
>> newfile echo.!S!
)
move /y newfile myfile


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions

#4
July 12, 2010 at 15:13:13
Hi,

Thank you very much for the script. My file name is not fixed.It can be anything.In that case will this code work?

Thanks,
Phani Akella


Report •

#5
July 12, 2010 at 15:35:09
@echo off > newfile & setLocal enableDELAYedeXpansion

if %1'==' echo which file? && goto :eof

for /f "tokens=* delims= " %%a in (%1) do (
set S=%%a
set S=!S:@=!
set S=!S:$=!
>> newfile echo.!S!
)
move /y newfile myfile


=====================================
Helping others achieve escape felicity

M2


Report •

#6
July 12, 2010 at 17:40:18
>> Can we do this with out sed?

sure, of course you can use batch like what M2 posted. That's one way. (since your requirement is simple)
sed is just one of the tools out there excellent for data processing and as you can see, its just one line of regular expression. If you have more complex task other than just replacing @ and $, eg dealing with XML, exchanging text around in a file, grepping for multiline patterns, etc, using batch will be a pain. Use the appropriate tools for the job.

GNU win32 packages | Gawk


Report •

#7
July 12, 2010 at 22:47:45
Hi Mechanix2Go,

I will get a file say "SampleFile.txt". Batch file should delete all @ and $ and save it back to "SampleFile.txt".

I mean to say that the file which I get is not constant I can be "SampleFile.txt" now and "SampleFile1000.txt" or Anything.txt.

In short bathc should go to the folder path D:/Test and open the file present starting with Sample*.txt and remove @ and $ and save the file with out changing its File name.

Thanks,
Phani Akella


Report •

#8
July 12, 2010 at 22:59:49
Hi Ghostdog,

Thanks you very much for the sed command. Can you please let me know few points like:

1. Do I need to download and install the Sed package?
2. Is is free or do i need to buy it?
3. Is this compatible on Win2003 and XP machines?

Thanks,
Phani Akella


Report •

#9
July 13, 2010 at 00:03:20
>> 1. Do I need to download and install the Sed package?
download from the link i gave in my first post. Install once only.
Its just an exe file, so you can bring it anywhere later.

>> 2. Is is free or do i need to buy it?
I never recommend anyone to buy things. Its GNU and its free to use.

>> 3. Is this compatible on Win2003 and XP machines?
Yes. Have you not looked at the link i gave? All the way to the bottom of the page , there is a list of windows compatibilities stated.

GNU win32 packages | Gawk


Report •

#10
July 19, 2010 at 17:17:33
Hi Experts,

Code is working great. But I would like to make it Dynamic, I mean no human intervention. I will schedule this batch job. I have to execute every 1 hr and should remove special chars for all the files which are present in the D:\Test directory.Batch should not change the File name...It should just open the file, remove the special chars and save the file back with its name.

Thanks,
Phani Akella


Report •

#11
July 19, 2010 at 17:41:31
if you had used sed, use the -i option to edit the file in place.
in your task scheduler, just insert the sed command when you create the task

GNU win32 packages | Gawk


Report •

#12
July 19, 2010 at 22:28:42
Hi ghostdog,

Thank you. I will try this. This is when we are using SED. How about if I am using batch file. Cant we achieve this using Batch file?

Thanks,
Phani Akella


Report •

#13
July 19, 2010 at 22:55:19
if you put sed in a .bat file and run it, its still called a batch file. Are you talking about pure cmd.exe commands? if you are, wait for someone who has the free time to suggest something for you...

GNU win32 packages | Gawk


Report •

Ask Question