| 1. |
Solve : Editing a file [automatically] through batch file?? |
|
Answer» This is probably a very very noob question It would be possible to do some kind of word-processing / text-editing type things to a file fairly simply, such as search & replace, change case, deletion, insertion, etc. How would one go about deleting (not ignoring) the first line of a text file using DOS?Using the "skip" setting in the FOR command, copy the file to another temp one, skipping the first line. Then delete the original file, and rename the temp file with the original file name. Here's what I got so far...and it's not working...Not sure what I'm doin wrong: For /F "skip=1" %%x in ("i:\shared_retention\ccbatch\ccbatch.txt") do copy %%x "i:\shared_retention\ccbatch\ccbatch2.txt" am I WAY off? Quote from: dvnmaya on March 03, 2008, 02:56:39 PM Here's what I got so far...and it's not working...Not sure what I'm doin wrong: Not far off really. You need ECHO, not COPY. The lines starting REM are REMarks and do not affect the operation of the batch file and can be removed if you want, as can the blank lines. I have PLACED the SOURCE and destination file names into variables to make the code a bit clearer but you can code them literally if you want, of course This should work... Code: [Select] set file1="i:\shared_retention\ccbatch\ccbatch.txt" set file2="i:\shared_retention\ccbatch\ccbatch2.txt" REM if the target file already exists, delete it if exist %file2% del %file2% REM Now the >> redirection will create the file the first time it is used REM to echo a line and append each line subsequently For /F "skip=1" %%x in (%file1%) do echo %%x >> %file2% |
|