IntercareSupport
asked on
Insert carraige return at the end of multiple files?
I have a directory of 770 text files. I need to insert a carraige return at the end of each file. What's the best way to do this? Batch file, powershell, perl-I don't care the coding style. Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect! Thanks!
@Steve, I think your idea of setting delims=" will still use the default of space and quote, not sure..
Also, I'm pretty sure that Windows CMD won't have this issue anymore, but I recall having issues where it would echo the command into the file if it was not told to mute echos of the command..
Also I noticed you accidentally left the Batch double % in the command on the A, which needs to be fixed.
@Author,
If you have any issues with the above try this:
At the Command Line of the computer where the files are:
At a Remote Command Line
In a Batch File for Local Directory:
In a Batch File for Remote File Location:
Also, I'm pretty sure that Windows CMD won't have this issue anymore, but I recall having issues where it would echo the command into the file if it was not told to mute echos of the command..
Also I noticed you accidentally left the Batch double % in the command on the A, which needs to be fixed.
@Author,
If you have any issues with the above try this:
At the Command Line of the computer where the files are:
@FOR /F "Tokens=*" %F ('DIR /B "Drive-Letter:\Path To\Text Files\*.txt" A:-D') DO @ECHO.>>"%~F"
At a Remote Command Line
@FOR /F "Tokens=*" %F ('DIR /B "\\ServerName\Share\Path To\Text Files\*.txt" A:-D') DO @ECHO.>>"%~F"
In a Batch File for Local Directory:
@ECHO OFF
SET "FullFilePath=Drive-Letter:\Location\Of Folder\With Files"
FOR /F "Tokens=*" %%F ('DIR /B "%FullFilePath%\*.txt" A:-D') DO ECHO.>>"%%~F"
Pause
In a Batch File for Remote File Location:
@ECHO OFF
SET "Server=ServerName or IP"
SET "FilePath=Share\Location\Of Folder\With Files"
FOR /F "Tokens=*" %%F ('DIR /B "\\%Server%\%FilePath%\*.txt" A:-D') DO ECHO.>>"%%~F"
Pause
Glad it helped... sorry for typos, was being jumped on at the time (young boys....)
lol, yeah, just missed the close of the posting too, couldn't have expected more than assist anyway.
Steve you always write good code, boys or no you answered it quickly and well.
-Q
Steve you always write good code, boys or no you answered it quickly and well.
-Q
@echo off
cd /d "C:\yourdir"
for /f "delims=" %%a in ('dir /b *.txt') do echo. >>"%%~a"
This should append a blank line (which is what echo. does) using >> to append to the end of each file it finds using the dir command.
Like I said try on a test file or two first!
Steve