Solved

Insert carraige return at the end of multiple files?

Posted on 2012-03-16
6
469 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 11

Expert Comment

by:Ben Personick
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 11

Expert Comment

by:Ben Personick
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now