读取各种txt文件中的行,在单行和单个文件中输出这些行

时间:2013-01-03 15:34:23

标签: batch-file

我非常基本的蝙蝠,需要帮助做一个脚本,在一行和一个文件上连接几个txt文件的行。 例如: 这些是文件:

W7BR71754L.txt

Relatório de Hardware:
Nome:W7BR71754L
S.O.:Microsoft Windows 7 Professional 
Usuário:GMEA\SESA197328
Serial:5CB2204XTP

W7BR71760L.txt

Relatório de Hardware:
Nome:W7BR71760L
S.O.:Microsoft Windows 7 Professional 
Usuário:GMEA\SESA97408
Serial:5CB2190BPX

newfile.txt

Relatório de Hardware:;Nome:W7BR71754L;S.O.:Microsoft Windows 7 Professional ;Usuário:GMEA\SESA197328;Serial:5CB2204XTP;
Relatório de Hardware:;Nome:W7BR71760L;S.O.:Microsoft Windows 7 Professional ;Usuário:GMEA\SESA97408;Serial:5CB2190BPX;

这是我正在努力的事情,但它并没有完全符合我的需要......

@echo off
setlocal EnableDelayedExpansion
set "text="
for /r %%G in (*.txt) do (call :sub "%%G")
:sub
for /f "tokens=*" %%a in (%1) do (
 set "text=!text!%%a"
)
>>newFile.txt echo !text!;

1 个答案:

答案 0 :(得分:1)

你几乎就在那里,只是将新行添加到你需要添加的文件中。

这会将所有文件文本连接成一个文件 - 每个文件的内容用一行分隔。

setlocal enabledelayedexpansion
set text=
for /r %%a in (*.txt) do (
for /f "tokens=* delims=" %%x in (%%a) do (
set text=!text!%%x
)
echo !text! >>newfile.txt
set text=
)