Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Insert carraige return at the end of multiple files?

Posted on 2012-03-16
6
Medium Priority
?
512 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 2000 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 14
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 14
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

671 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