Copy file, changing contents

June 29, 2009 at 11:07:47
Specs: Windows XP
I need a script to read records from a file, strip
everything up to and including the first "," character from
the record, then write the record to another file.

Thanks,
Pete


See More: Copy file, changing contents

Report •


#1
June 29, 2009 at 12:42:35
@echo off > output.txt
for /F "tokens=1,* delims=," %%j in ('type "input.txt"') do echo.%%k>> output.txt


Report •

#2
June 29, 2009 at 13:04:42
Thanks for the quick response, that helps me out a lot!
Pete

Report •

#3
June 29, 2009 at 17:56:36
if you have gawk for windows (see my sig)
c:\test> gawk -F"," "{$1=\"\";}{sub(/^,/,\"\")}1" OFS="," file.txt

GNU win32 packages | Gawk


Report •

Related Solutions

#4
June 29, 2009 at 18:04:13
Thanks for both replies. One follow up question - can the
changed data be written back to the same file rather than
output to a different file?
Thanks,
Pete

Report •

#5
June 29, 2009 at 23:19:38
Sorry, one more thing on this. Is there a way to check if the
input file exists before executing the commands? I'm finding
that if the input file does not exist, an empty output file is
created which causes problems.
Thanks,
Pete

Report •

#6
June 30, 2009 at 04:11:46
:: MYCOPY.BAT Usage: mycopy "Pathname_Filename"
@echo off
if not exist "%~1" (echo.File "%~1" not found & goto :EOF) 
type nul > "%~dpn1.tmp"
for /F "tokens=1,* delims=," %%j in ('type "%~1"') do echo.%%k>> "%~dpn1.tmp"
del "%~1"
ren "%~dpn1.tmp" "%~1"
echo.File "%~1" was copied and edited.
:: End_Of_Batch

example: mycopy "C:\Documents and Settings\My data\FileIn.txt"

Don't miss the double quotes embracing filename.


Report •

#7
June 30, 2009 at 10:23:17
Thanks a lot, that all works perfectly!

Report •

#8
August 18, 2009 at 13:13:56
This code has been working fine for me for several months.
Just started to use it on a file that contains some html code
and it's not handling it very well.

The file looks something like this:

2,words words words!

<form action="https://www.paypal.com/cgi-bin/webscr" 
method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" 
value="7449166">
<input type="image" 
src="https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gi
f" border="0" name="submit" alt="PayPal - The safer easier 
way to pay online!">
<img alt="" border="0" 
src="https://www.paypal.com/en_US/i/scr/pixel.gif" 
width="1" height="1">
</form>

There's actually an html line break tag after "words" but it's getting interpreted as a real line break in this message so you don;t see it.

AFter processing the file looks like this:

words words words

Everything after the line break tag is replaced with white space.

Any ideas?

Thanks,
Pete


Report •


Ask Question