Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 3rd, 2013, 12:59 PM
tentson tentson is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 3 tentson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 56 sec
Reputation Power: 0
Need .vbs code to swap columns in .txt files

hi all, sorry for i am a newbie in .vbs. here is my problem:

i have a text file consisting of more than 20k lines, and with a fixed column width. example of data is below:

Column 1 - 36 ----Column 37 - 72----- -Column 73 - 91----
Abcd Efdrsdfg 123456678901234567890 540040001610082805
Abcd Efdrsdfg 123456678901234567890 540040001610082805
Abcd Efdrsdfg 123456678901234567890 540040001610082805
Abcd Efdrsdfg 123456678901234567890 540040001610082805
Abcd Efdrsdfg 123456678901234567890 540040001610082805
Abcd Efdrsdfg 123456678901234567890 540040001610082805
Abcd Efdrsdfg 123456678901234567890 540040001610082805
Abcd Efdrsdfg 123456678901234567890 540040001610082805
Abcd Efdrsdfg 123456678901234567890 540040001610082805
Abcd Efdrsdfg 123456678901234567890 540040001610082805
Abcd Efdrsdfg 123456678901234567890 540040001610082805

now, what i want to do is, swap column 37-72 to column 73-91. with the same .txt file. how can i do this using .vbs script to make is automatic.

thank you in advance.

Reply With Quote
  #2  
Old March 4th, 2013, 01:29 AM
couttsj couttsj is online now
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 170 couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 18 h 22 m 34 sec
Reputation Power: 43
I suspect what you have supplied is not real data, as the lines are all identical. If what you are after is to sort the file starting at column 73, the easiest and fastest way is to use the type command, and pipe the results to the sort command, and output to a new file.

type file1.txt|sort /+73>file1A.txt

J.A. Coutts

Reply With Quote
  #3  
Old March 4th, 2013, 06:44 AM
tentson tentson is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 3 tentson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 56 sec
Reputation Power: 0
data is only a representation to show what my problem is. since the real data contains confidential files. can you provide me of a script?

Reply With Quote
  #4  
Old March 9th, 2013, 02:58 PM
GGriggs GGriggs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 18 GGriggs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 45 m 43 sec
Reputation Power: 0
not worth bothering with VB

Cut and paste text into column A of an excel spreadsheet
cell B1 = =left(a1,36)&mid(a1,73,19)&mid(a1,37,36)
drag the formula down to the end of your data
cut and paste back to your doc

use Table>Convert>Table to text if you need it as text rather than a table

takes approx 30 secs total

Reply With Quote
  #5  
Old March 10th, 2013, 11:43 AM
tentson tentson is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 3 tentson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 56 sec
Reputation Power: 0
Thank you even if nobody is able to help me, anyways i did find the solution to my problem. The code is below in case others will meet the same problem as mine, this might help.

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set outPut = objFSO.CreateTextFile("C:\test1.txt", true)
Set objTextFile = objFSO.OpenTextFile("C:\test.txt", ForReading)

Do Until objTextFile.AtEndOfStream
strLine = objTextFile.Readline
col1 = Mid(strLine, 1, 13)
col2 = Mid(strLine, 37, 20)
col3 = Mid(strLine, 73, 18)
outPut.WriteLine(col1 & " " & col3 & " " & col2)
Loop

outPut.Close()
Set objFSO = Nothing
Set outPut = Nothing

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Need .vbs code to swap columns in .txt files

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap