| 1. |
Solve : Add single comma in place of any number of spaces? |
|
Answer» Looking for a way to add a (SINGLE comma) in between data like below to force non comma delimited data to become comma delimited...any suggestions on how I can do this for a text document with the raw data like below in a batch ( or vb script ) so that I dont have to run this manual notepad replace 3 step process for daily data? How can I do the same thing with my data set? First row is my column headings comma « Sent to: ry8200 on: Today at 06:03:57 PM » | Reply | Quote | Delete | Code: [Select]@echo off & setLocal EnableDELAYedeXpansion del otfile.txt > nul for /f "delims=" %%i in (infile.txt) do ( call :sub %%i ) echo. type otfile.txt goto :eof :sub echo %* :loop echo/|set /p ="%1," >> otfile.txt shift if "%1"=="" ( goto :end ) goto :loop :end echo. >> otfile.txt Output: c:\test>comma2.bat 134-2 [emailprotected] MikeSmith 927 yes no 134-2 [emailprotected] MikeSmith 927 yes no 134-2 [emailprotected] MikeSmith 927 yes no 134-2 [emailprotected] JoeLong 927 yes no no yes 134-2,[emailprotected],MikeSmith,927,yes,no, 134-2,[emailprotected],MikeSmith,927,yes,no, 134-2,[emailprotected],MikeSmith,927,yes,no, 134-2,[emailprotected],JoeLong,927,yes,no,no,yes, c:\test> ref: http://stackoverflow.com/questions/4479734/echo-with-no-new-line-cr-lf That kind of work can be done by a spreadsheet program.1. This thread has been revived by ry8200 after a gap of over two and a half years. ry8200, if you are genuine, and not Bill's sock puppet, as certain internal evidence suggests, start your own thread. Better still, read this one, where the solution was clearly described by my friend Dias de Verano, in February 2009. 2. Fred35 is, as I suspected ever since he first appeared, Billrich. Honestly Salmon Trout - Sock puppet??? Are you kidding me... If this is how a new person is treated in this forum, then I'll take my request somewhere else. I am a real person with an issue that falls in line with this post and the previous issue that DaveLembke had; so I thought it would make sense to revive this post. Anyway, moving on. The new issue I'm having is two of the fields of data, called "fn" and "display" have spaces in them (for example "Display" = "John Smith D1234567"), that I need to keep, but I want to replace all the other spaces with a comma. The data pulled from my DSQUERY is: samid upn fn ln display canchpwd pwdneverexpires disabled 123-2 [emailprotected] John Smith D1234567 John Smith D1234567 yes no no 456-2 [emailprotected] Mike Smith U1234567 Mike Smith U1234567 yes no no The output would need to look like this: samid,upn,f,ln,display,canchpwd,pwdneverexpires,disabled 123-2,[emailprotected],John Smith,D1234567,John Smith D1234567,yes,no,no 456-2,[emailprotected],Mike Smith,U1234567,Mike Smith U1234567,yes,no,no Did you read what was said about starting your own thread? You have revived a thread from 2009. Anyhow, @echo off setlocal enabledelayedexpansion set InputFileName=Input.txt set OutputFileName=output.csv set line=1 if exist "%OutputFileName%" del "%OutputFileName%" for /f "tokens=1-11 delims= " %%A in ('type "%InputFileName%"') do ( if !line! equ 1 ( set output=%%A,%%B,%%C,%%D,%%E,%%F,%%G,%%H ) else ( set output=%%A,%%B,%%C %%D,%%E,%%F %%G %%H,%%I,%%J,%%K ) echo !output! >> "%OutputFileName%" set /a line+=1 ) echo Input: echo. type "%InputFileName%" echo. echo Output: echo. type "%OutputFileName%" Input: samid upn fn ln display canchpwd pwdneverexpires disabled 123-2 [emailprotected] John Smith D1234567 John Smith D1234567 yes no no 456-2 [emailprotected] Mike Smith U1234567 Mike Smith U1234567 yes no no Output: samid,upn,fn,ln,display,canchpwd,pwdneverexpires,disabled 123-2,[emailprotected],John Smith,D1234567,John Smith D1234567,yes,no,no 456-2,[emailprotected],Mike Smith,U1234567,Mike Smith U1234567,yes,no,no |
|