remove characters in file by passing in file

Microsoft Windows server 2000 w/ sp2
December 29, 2009 at 09:48:00
Specs: Windows Server 2000
i'm a dos command beginner and would like help on how to create a batch script to pass in a file name and remove the first character in the file..I would like to remove the # from the first line in an out file.
#Account|Date|Name

I've tried this code from this forum but it doesnt seems to work. Please help

@echo off > newfile & setLocal enableDELAYedexpansion

for /f "tokens=* delims= " %%a in (myfilename.txt) do (
set str=%%a
set str=!str:#=!
>> newfile echo !str!
)


See More: remove characters in file by passing in file

Report •


#1
December 29, 2009 at 11:51:37
i ran it and it worked ok. i changed this line:
for /f "tokens=* delims= " %%a in (myfilename.txt) do (

i would recommend removing the space after "delims":
for /f "tokens=* delims=" %%a in (myfilename.txt) do (

that was the only change i made.
what, specifically, is going wrong?


Report •

#2
December 29, 2009 at 14:08:49
I've tried again and it works. Nothing was wrong, more like user errors.

I want to change the script to do something else with the same concept. Hope you can help.

I want to remove the # character for all the files in the directory. How can I edit to remove without creating new files? Or is this a neccessary?

Here is what I have so far that I got from this forum. I don't want to have a new file (#) created but if I remove the echo and copy to # it doesn't work
@echo off & setLocal enableDELAYedexpansion

for /f "tokens=* delims= " %%a in ('dir /b AA*.txt') do (
set N=0
for /f "tokens=* delims= " %%i in (%%a) do (
set /a N+=1
if !N! equ 1 (
set str=%%i
set front=!str:~1!
echo !front! > #
) else (
echo %%i >> #
)
)
copy # %%a
)


Report •

#3
December 29, 2009 at 16:00:12
download GNU sed (see my sig) and on command line

c:\test> sed  -i.bak "s/\#//g" file*.txt

GNU win32 packages | Gawk


Report •

Related Solutions

#4
December 30, 2009 at 02:23:22
@echo off > newfile & setLocal enableDELAYedeXpansion


for /f "tokens=* delims= " %%a in ('dir /b AA*.txt') do (
del newfile
for /f "tokens=* delims= " %%i in (%%a) do (
set str=%%i
set str=!str:#=!
>> newfile echo !str!
)
copy newfile %%a > nul
)
del newfile


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

M2


Report •


Ask Question