Split Data in one column into 2 column in Excel using DOS or VBScript

 
Thread Tools Search this Thread
Special Forums Windows & DOS: Issues & Discussions Split Data in one column into 2 column in Excel using DOS or VBScript
# 1  
Old 03-12-2010
Split Data in one column into 2 column in Excel using DOS or VBScript

Hi

I have some data in my Excel File.However all the data is in one single column.I want to split it into two columns.

Current Data:

1,Hi Everyone,I am
7,New To Dos,And
17,VB Script,i could
110,have tried this thing
1800,in UNIX

Desired Output
CELL1|CELL 2
1 |Hi Everyone,I am
7 |New To Dos,And
17 |VB Script,i could
110 |have tried this thing
1800 |in UNIX

Basically I wanted to search for first comma and then put content after that to second column.

Share some suggestions pls.
Any DOS command or VB Script will be fine.
# 2  
Old 03-12-2010
The scriptname should have .vbs as extension, the output goes to the file Outfile:

Code:
Dim filesys, Infile, Outfile, pos

Const ForReading = 1, ForWriting = 2 

file = InputBox("Filename : ")

if file = "" then
  WScript.Quit
end if

Outfile = "Outfile"

Set filesys = CreateObject("Scripting.FileSystemObject")

If NOT filesys.FileExists(file) Then
  msgbox("File " & file & " not found!")
  WScript.Quit
End If 

Set Infile = filesys.OpenTextFile(file, ForReading, True)
Set Outfile = filesys.OpenTextFile(Outfile, ForWriting, True)

do while Infile.AtEndOfStream <> true
  Line = Infile.readline
  pos = instr(Line,",")
  Line = Left(Line, pos - 1) & "|" & Mid(Line, pos + 1)
  Outfile.WriteLine(Line)
loop

Infile.Close
Outfile.Close

Set Infile = Nothing
Set Outfile = Nothing
Set filesys = Nothing

MsgBox("Ready")

Regards
# 3  
Old 03-12-2010
Hi Franklin52

Thanks for the reply !
However '|' here does not mean PIPE delimited it means new column in Excel Sheet.
Any inputs ?
# 4  
Old 03-12-2010
Quote:
Originally Posted by dashing201
Hi Franklin52

Thanks for the reply !
However '|' here does not mean PIPE delimited it means new column in Excel Sheet.
Any inputs ?
Replace the pipe symbol with your delimiter on this line:

Code:
Line = Left(Line, pos - 1) & "|" & Mid(Line, pos + 1)

For instance, if you want a tab you can use the constant vbTab:

Code:
Line = Left(Line, pos - 1) & vbTab & Mid(Line, pos + 1)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to copy a column of multiple files and paste into new excel file (next to column)?

I have data of an excel files as given below, file1 org1_1 1 1 2.5 100 org1_2 1 2 5.5 98 org1_3 1 3 7.2 88 file2 org2_1 1 1 2.5 100 org2_2 1 2 5.5 56 org2_3 1 3 7.2 70 I have multiple excel files as above shown. I have to copy column 1, column 4 and paste into a new excel file as... (26 Replies)
Discussion started by: dineshkumarsrk
26 Replies

2. UNIX for Beginners Questions & Answers

How to insert data into black column( Secound Column ) in excel (.XLSX) file using shell script?

Source Code of the original script is down below please run the script and try to solve this problem this is my data and I want it column wise 2019-03-20 13:00:00:000 2019-03-20 15:00:00:000 1 Operating System LAB 0 1 1 1 1 1 1 1 1 1 0 1 (5 Replies)
Discussion started by: Shubham1182
5 Replies

3. Shell Programming and Scripting

Split column when value in column is blank in any row

Hi Experts, In short : Need to split file when field in column 5 is blank and need to generate two file in which column 5 is blank and other in which column 5 has values along with other rows and column data My issue is i am not able to get header for column from raw file into new file which... (1 Reply)
Discussion started by: as7951
1 Replies

4. Shell Programming and Scripting

Split column data if the table has n number of column's with some record

Split column data if the table has n number of column's with some record then how to split n number of colmn's line by line with records Table --------- Col1 col2 col3 col4 ....................col20 1 2 3 4 .................... 20 a b c d .................... v ... (11 Replies)
Discussion started by: Priti2277
11 Replies

5. Shell Programming and Scripting

Split column data if the table has n number of column's

please write a shell script Table -------------------------- 1 2 3 a b c 3 4 5 c d e 7 8 9 f g h Output should be like this --------------- 1 2 3 3 4 5 7 8 9 a b c c d e f g h (1 Reply)
Discussion started by: Priti2277
1 Replies

6. Shell Programming and Scripting

Insert data in first column(if blank) from previous line first column

Dear Team I need to insert field(which is need to taken from previous line's first field) in first column if its blank. I had tried using sed but not find the way. Detail input and output file as below. Kindly help for same. INPUT: SCGR SC DEV DEV1 NUMDEV DCP ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

7. Shell Programming and Scripting

awk to sum a column based on duplicate strings in another column and show split totals

Hi, I have a similar input format- A_1 2 B_0 4 A_1 1 B_2 5 A_4 1 and looking to print in this output format with headers. can you suggest in awk?awk because i am doing some pattern matching from parent file to print column 1 of my input using awk already.Thanks! letter number_of_letters... (5 Replies)
Discussion started by: prashob123
5 Replies

8. Shell Programming and Scripting

Compare 2 files and match column data and align data from 3 column

Hello experts, Please help me in achieving this in an easier way possible. I have 2 csv files with following data: File1 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:36:09,JOB_5340 08/23/2012 12:36:14,JOB_5340 08/23/2012 12:36:22,JOB_5350 08/23/2012... (5 Replies)
Discussion started by: asnandhakumar
5 Replies

9. Shell Programming and Scripting

Excel file attachment showing data in single column

Hi All, found similar posts, but not exatcly what i wanted. I have an text file like below and am trying to send mail as an excel file but when i get the excel file as the attachment, all the data is coming in the first column. I need below data in 4 columns. Unix file Name,ID,Trade,Date... (3 Replies)
Discussion started by: robinbannis
3 Replies

10. Shell Programming and Scripting

Replace column that matches specific pattern, with column data from another file

Can anyone please help with this? I have 2 files as given below. If 2nd column of file1 has pattern foo1@a, find the matching 1st column in file2 & replace 2nd column of file1 with file2's value. file1 abc_1 foo1@a .... abc_1 soo2@a ... def_2 soo2@a .... def_2 foo1@a ........ (7 Replies)
Discussion started by: prashali
7 Replies
Login or Register to Ask a Question