Solved

Insert carraige return at the end of multiple files?

Posted on 2012-03-16
6
460 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
Comment Utility
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
Comment Utility
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
Comment Utility
Perfect!  Thanks!
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 11

Expert Comment

by:Ben Personick
Comment Utility
@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
Comment Utility
Glad it helped... sorry for typos, was being jumped on at the time (young boys....)
0
 
LVL 11

Expert Comment

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

13 Experts available now in Live!

Get 1:1 Help Now