text file with multiple rows to 1 row tab delimited or comma

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mydtt
Posts: 1
Joined: 09 Aug 2011 15:58

text file with multiple rows to 1 row tab delimited or comma

#1 Post by mydtt » 09 Aug 2011 16:06

I have text file that looks like this:

***** HOST NAME: *****
HX-2UA0410KKK
***** LOGMEIN ID: *****
HostDescription REG_SZ store-49877
***** PORTAL CLIENT GUID: *****
f7bca0bf-08e0-4095-89f4-00620d123456

***** GEO HEALTH: *****
[Multicam]
HSchedule=0
UseSoftWatchDog=1
exepath=C:\DTT3330\DM500Startup.exe
SWDogActive=(2011- 8- 9 3: 2:59)

I need it to look like:

***** HOST NAME: *****, HX-2UA0410C3J,***** LOGMEIN ID: *****, HostDescription REG_SZ store-49877, ***** PORTAL CLIENT GUID: *****, f7bca0bf-08e0-4095-89f4-00620da48a60, and so on...

I think you get the picture.

Any assistance would be create is you could recommend a program that can modify multiple texts files or a way to script this using a batch. Thank you!

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: text file with multiple rows to 1 row tab delimited or c

#2 Post by dbenham » 09 Aug 2011 23:58

The key trick is to output text without issuing a newline:

Code: Select all

<nul set /p =   This will "echo" without a new line but leading spaces are stripped.
Unfortunately I'm not aware of a way to preserve leading spaces.

Complete solution if you don't care about preserving empty lines:

Code: Select all

@echo off
setlocal
set infile="test.bat"
set outfile="test.out"
if exist %outfile% del %outfile%
for /f "usebackq tokens=* eol= delims= " %%a in (%infile%) do <nul set/p=%%a,>>%outfile%

If you want to preserve empty lines as empty fields:

Code: Select all

@echo off
setlocal
set infile="input.txt"
set outfile="test2.out"
if exist %outfile% del %outfile%
for /f "skip=2 delims=" %%a in ('find /v /n "" %infile%') do (
  set ln=%%a
  setlocal enableDelayedExpansion
  <nul set/p=!ln:*]=!,>>%outfile%
  endlocal
)


Dave Benham

Post Reply