在 DOS 中获取文件同一行的输出?
如果我想将两个来源的输出放在同一行上,我该怎么做?
就我而言,我有一个文件和一个程序。该文件是这样的:
listOfThings=
我的程序在一行上输出字符串列表。我想要一个每晚运行的小脚本,将这两件事放在一行上。我无法弄清楚如何正确执行此操作,但
示例批处理文件
type header.txt > outputfile.txt
myProgram >> outputfile.txt
会导致以下结果:
listOfThings=
foo bar baz etc
我确实需要输出文件将列表立即跟在 = 之后,但我不知道如何使用 > 来做到这一点>操作员。 (在有人建议之前,我不能做类似在 listOfThings= 行末尾添加 \ 的事情,这对我想做的事情不起作用)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要确保 header.txt 的内容中没有回车换行符对。用十六进制编辑器查看并确保其中没有 0x0d0a。
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.
您是否确保 header.txt 中根本没有任何行分隔符? (即,= 是文件的最后一个字节)。
另外,请尝试将 header.txt 复制到 outputfile.txt,以防 type 自行附加换行符。
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.