How to append a CR to end of all .txt files in a directory

1

Is there an easy way to do this? I'm actually combining about 500 files using copy *.txt myoutputFile.txt. The problem is, that command inserts the new/next file at the current/end position of the file, where I need it to be inserted on a new line.

MisterIsaak

Posted 2013-07-25T02:28:48.027

Reputation: 111

Answers

0

for f in *.txt
do
  echo -e -n '\n' >> "$f"
done

Ignacio Vazquez-Abrams

Posted 2013-07-25T02:28:48.027

Reputation: 100 516

1just echo >> "$f" would work... but OP's use of 'copy' infers OP is on a windows box. Alas. You'd have to create a file containing a CR, then y'know... it's just painful to do it on a Windows box. Wait! There's Quickbasic scripts in MS Word! To the BatMobile!! (Ain't gonna do it!) Even using a Linux LiveCD would be faster. – lornix – 2013-07-25T02:58:16.380

on windows , one place they suggest "do more" | for %%a in (*.txt) do more %%a >>file.doc | . and not using a .txt extention on the output so a loop doesnt occur. This method for the merging puts them on seperate lines, so no need to add to each file. – Psycogeek – 2013-07-25T03:23:46.267

0

I decided to just make a quick VBScript:

Dim fso, folder, files
Dim strPath

Const ForAppending = 8

' Create a FileSystemObject  
Set fso = CreateObject("Scripting.FileSystemObject")

' Define folder we want to list files from
strPath = "C:\members"

Set folder = fso.GetFolder(strPath)
Set files = folder.Files

' Loop through each file  
For each item In files

set textFile = FSO.OpenTextFile(item, ForAppending)

textFile.WriteLine()
textFile.Close()
Next

MisterIsaak

Posted 2013-07-25T02:28:48.027

Reputation: 111