Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

@echo off > output.txt for /F "tokens=1,* delims=," %%j in ('type "input.txt"') do echo.%%k>> output.txt

if you have gawk for windows (see my sig)
c:\test> gawk -F"," "{$1=\"\";}{sub(/^,/,\"\")}1" OFS="," file.txt

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

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

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

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 wordsEverything after the line break tag is replaced with white space.
Any ideas?
Thanks,
Pete

![]() |
![]() |
![]() |

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