Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combine 2 columns in .VSB

Status
Not open for further replies.

ScottWDieterle

Technical User
Sep 11, 2012
4
US
I have a .CSV file and I am trying to combine the first 2 columns.

IE
input
Scott,Dieterle,219,N,Hale,Ave

Output
ScottDieterle,219,H,Hale,Ave

Any help would be appreciated. I am new to .bat and .vbs and trying to learn as I go!
 
There are a couple ways. A) Use an Excel instance (Others may be able to show you this method). B) Simply remove the first comma of each line. C) touch each element of data ("universal").

First, in notepad, does a file look like this: (typical csv formatting)
"Scott","Dieterle","219","N","Hale","Ave"

or like this:
Scott,Dieterle,219,N,Hale,Ave

-Geates

"I do not offer answers, only considerations."
- Geates's Disclaimer

 
it is a .csv file that looks like this

Scott,Dieterle,219,N,Hale,Ave

The file comes out of a program that I run, I have to strip the first comma manually in excel

Need a script to just strip off the first comma

I will create a .bat to move the file to an FTP site
 
[red]1. open the .csv [/red]
[green]2. traverse each line[/green]
[blue]3. remove first comma[/blue]
[purple]4. write to output[/purple]

Code:
[red]set objFSO = CreateObject("Scripting.FileSystemObject")
set objInput = objFSO.OpenTextFile("C:\myFile.csv", 1, true, 0)[/red]
[purple]set objOutput = objFSO.OpenTextFile("C:\myFile2.csv", 2, true, 0)[/purple]

[green]do while not objInput.AtEndOfStream
   strInLine = objInput.ReadLine
   [blue]strOutLine = replace(strInLine, ",", "", 1)  'replace only the first instance of a comma [/blue]
   [purple]objOutput.WriteLine strOutLine[/purple]
loop
[/green]

objInput.close
objOutput.close

-Geates

"I do not offer answers, only considerations."
- Geates's Disclaimer

 
This worked but now the output file has no commas in it?

set objFSO = CreateObject("Scripting.FileSystemObject")
set objInput = objFSO.OpenTextFile("C:\reports\classdataFile.csv", 1, true, 0)
set objOutput = objFSO.OpenTextFile("C:\reports\classdatfile1.csv", 2, true, 0)

do while not objInput.AtEndOfStream
strInLine = objInput.ReadLine
strOutLine = replace(strInLine, ",", "", 1) 'replace only the first instance of a comma
objOutput.WriteLine strOutLine
loop


objInput.close
objOutput.close
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top