views:

65

answers:

2

If I have output from two sources that I want to put together on the same line, how would I do that?

In my case I have a file and a program. The file is something like this:

listOfThings=

My program outputs a list of strings on a single line. I want have a small script that runs nightly to put these two things together on a single line. I can't figure out how to do this right though

example batch file

type header.txt > outputfile.txt
myProgram >> outputfile.txt

which results in this:

listOfThings=
foo bar baz etc

I really need the output file to have the list immediately follow the =, but I can't figure out how to do it with the >> operator. (and before anyone suggests it, I can't do something like put a \ on the end of the listOfThings= line, that won't work for what I'm trying to do)

A: 

Have you made sure that header.txt doesn't have any line separators in it at all? (Ie, the = is the very last byte of the file).

Also, try copying header.txt to outputfile.txt in case type is appending a line feed on it's own.

developmentalinsanity
The problem with that is that when I run the script every night it would just append the programs output every time, getting longer and longer each time.
Alex
+1  A: 

You need to make sure that the contents of header.txt does not have a carriage return linefeed pair in it. Look at it with a hex editor and make sure there is no 0x0d0a in it.

Mark Wilkins
I just doubled checked, and the last characters area indeed 0x0d0a, and no newlines or anything. I suspect that type is appending a newline to the end. :(
Alex
The 0x0d0a is the newline sequence. Maybe I'm not quite following, but if you remove those from header.txt, then they will not end up in outputfile.txt. Before I posted the answer, I created a text file with no linefeed at the end and then did a "type myfile.txt > newfile.txt" and no line feeds were added. But I'm using 4DOS, maybe it behaves differently. I'll check.
Mark Wilkins
I just tried with a DOS prompt fired up with cmd.exe and don't get any linefeed sequences if the original file does not have any.
Mark Wilkins
I'm clearly not thinking straight today. :-/ I misread your post. All is well now though. :D
Alex