在Windows中,如何将一个文本文件中的多行合并为一行? [英] How to combine multiple lines in a single text file into one line, in Windows?

查看:370
本文介绍了在Windows中,如何将一个文本文件中的多行合并为一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个遵循此格式的标准文本文件,每个文件中的行数有所不同:

I have a multiple standard text files that follow this format, with varying numbers of lines in each file:

Line1
Line2
Line3
Line4

我想将每一行合并为一行,并在每组字符之间留一个空格,因此文本文件应如下所示:

I want to merge every line into one, with a space in between each set of characters, so the text file would look as such:

Line1 Line2 Line3 Line3

...等等.由于每个文本文件包含不同的行数,因此这需要使用任意给定的行数.我的意图是 not 合并文本文件中的行;我希望每个文本文件都保持独立.我在网上找到的所有解决方案都不太适合此解决方案,或者只能与UNIX一起使用.我正在运行Windows7.这可以在Powershell,VBS,批处理或特定程序中完成,没关系,只需要与Windows一起使用即可.

...and so on. This needs to work with any given number of lines, due to the fact that each text file contains a different number of lines. My intention is not to merge the lines in the text files; I want each text file to remain separate. All the solutions I have found online either don't quite fit this or work exclusively with UNIX. I am running Windows 7. This can be done in Powershell, VBS, Batch, a particular program, doesn't matter, it just needs to work with Windows.

非常感谢!

推荐答案

使用批处理:

for /f "usebackqdelims=" %%i in ("infile.txt") do @<nul set /p"=%%i ">>"outfile.txt"
>>"outfile.txt" echo.

这篇关于在Windows中,如何将一个文本文件中的多行合并为一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆