Solved

Insert carraige return at the end of multiple files?

Posted on 2012-03-16
6
489 Views
Last Modified: 2012-03-16
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!
0
Comment
Question by:IntercareSupport
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37730862
OK make sure you have a backup then try this:

@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
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 37730868
I should have said leave out the extra space there between the . and >> otherwise you actually get a space then newline appended, which may or not matter.

Or from command line just leave out one of the %'s:

cd /d c:\yourdir
for /f "delims=" %a in ('dir /b *.txt') do echo.>> "%%~a"

Steve
0
 

Author Closing Comment

by:IntercareSupport
ID: 37731202
Perfect!  Thanks!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12
ID: 37731206
@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:
@FOR /F "Tokens=*" %F ('DIR /B "Drive-Letter:\Path To\Text Files\*.txt" A:-D') DO @ECHO.>>"%~F"

Open in new window


At a Remote Command Line
@FOR /F "Tokens=*" %F ('DIR /B "\\ServerName\Share\Path To\Text Files\*.txt" A:-D') DO @ECHO.>>"%~F"

Open in new window



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

Open in new window



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

Open in new window

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 37731253
Glad it helped... sorry for typos, was being jumped on at the time (young boys....)
0
 
LVL 12
ID: 37731762
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
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will help you understand what HashTables are and how to use them in PowerShell.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question