Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Add line to text file automatically

Author  Topic 

tyson27
Starting Member

2 Posts

Posted - 2009-09-10 : 13:53:17
Hi,
I'd like to make a batch file which would simply add one or more lines of text to the beginning a file and I'd like to be able to automatically update the file through running the batch file.

For example, lets say the text file contains:

Martha Stewart
220 Mandarine Honey Road
Prince Edwards Island, Fantasy Land
724-ASK-MARTHA

and I'd like to add the following line:

Status: active

final output should be:

Status: active
Martha Stewart
220 Mandarine Honey Road
Prince Island, Fantasy Land
724-ASK-MARTHA


I have this:
echo Status: active >>C:\test.txt

This will add the line at the end. I want it at the top, at the beginning of the text file.
Also this test file is generated as a result of running a stored procedure. So the naming convention of this text file is name_currentdateandtime.txt

So in this case how to add the line.
Should it be added in a batch file or in the stored procedure itself.

Thanks for any help

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-09-10 : 19:08:07
Create a text file with one line in it and name it a.txt. Bcp the data out to a different file.

Then concat them together using "type *.* > concat.txt". It does it alphabetically, so that's why I use a.txt for the first file. If I need stuff appended at the end, I use z.txt.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -