473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Format a file to get desired output using VBScript

Hello ,

I tried a code which reads the file InputFile.txt (attached) grep particular values and write it to a file in a desired output format is in file OutputFile.txt

Below is the code partially I have done..

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim re, targetString, colMatch, objMatch, nMT
  3.  
  4. Set objFS = CreateObject("Scripting.FileSystemObject")
  5.  
  6. Set rs = New RegExp
  7.  
  8. strFileIN = "..\Inputfile.txt"
  9. strFileOUT = "..\Outputfile.txt"
  10.  
  11. With rs
  12.   .Pattern = "\w+\(\w\.+\)" & "\w+\(\w+\)" 
  13.   .Global = True
  14.   .IgnoreCase = True
  15. End With 
  16.  
  17. Set objFile = objFS.OpenTextFile(strFileIN)
  18. strText = objFile.ReadAll
  19.  
  20.  
  21.  
  22. Set colMatch = rs.Execute(strText)
  23.  
  24. Set objOutFile = objFS.CreateTextFile(strFileOUT,True)    
  25.  
  26.  
  27. For nMT = 0 To colMatch.Count - 4
  28.  
  29. objOutFile.WriteLine colMatch(nMT + 0) &" "& colMatch(nMT + 1) &" "& colMatch(nMT + 2) &" "& colMatch(nMT + 3)
  30.  
  31. Next 
  32.  
  33.  
  34.  
  35. objOutFile.Close
  36.  
  37.  
Help me on correcting my code to get to my desired output as in file OutputFile.txt.
Attached Files
File Type: txt InputFile.txt (847 Bytes, 457 views)
File Type: txt OutputFile.txt (280 Bytes, 382 views)
Aug 14 '12 #1
10 2640
Rabbit
12,516 Expert Mod 8TB
You haven't said what is wrong with the code. Not working is too general a statement.

Also, since VBS is closer to VBA than VB6, I'm moving this to the Access forum where you may get more help.
Aug 14 '12 #2
QUEUE(TEST.QA.Q1) TYPE(QLOCAL)
CURDEPTH(0) MAXDEPTH(100000)

On my inputfile.txt , How do I form the regular expression pattern to match above pattern's. pls note word "TEST.QA.Q1" may change and the words delimited by "." dots may vary in numbers.

The pattern That i formed in my code didn't match QUEUE(TEST.QA.Q1).
Aug 14 '12 #3
Rabbit
12,516 Expert Mod 8TB
Your regex pattern is malformed. It should be \w+\([\w\.]+\)
Aug 14 '12 #4
Thanks Rabbit . It worked. I will try my code.
Aug 14 '12 #5
Expand|Select|Wrap|Line Numbers
  1. QUEUE(Q1.A1.C3.TEMP)         TYPE(QLOCAL)
  2.    CURDEPTH(0)                             MAXDEPTH(1000)


How to take values between ( and ) parenthesis and assign it to a variable ? I tried with mid function, but since my number of characters change it is not a solution. Do we have a special function ?



Expand|Select|Wrap|Line Numbers
  1. QUEUE=Q1.A1.C3.TEMP TYPE=QLOCAL CURDEPTH=0 MAXDEPTH=1000
Aug 16 '12 #6
Rabbit
12,516 Expert Mod 8TB
You already have the pattern, it's the one I posted earlier.
Aug 16 '12 #7
Corrected my question to be specific. Please check now.
Aug 16 '12 #8
Rabbit
12,516 Expert Mod 8TB
You can use the replace function.
Aug 16 '12 #9
Mariostg
332 100+
You are probably looking after placeholders ($1, $2) to use the expression you put between parenthesis in your regular expression. Here is an exemple I have in my codes. It takes a line of text, search for numbers having a negative sign at the end and move it at the beginning of the number.
Expand|Select|Wrap|Line Numbers
  1. Function BringForwardNegativeSign(LineToFix As String) As String
  2. 'This is to put negative sign in front 6.54- to -6.54 that exist in the DRMIS file.
  3.     Dim re As New RegExp
  4.     re.pattern = "\|( +)([0-9]*,?[0-9]*,?[0-9]*\.[0-9]{2})-"
  5.     re.Global = True
  6.     If (re.test(LineToFix) = True) Then
  7.         BringForwardNegativeSign = re.Replace(LineToFix, "|$1-$2")
  8.     Else
  9.         BringForwardNegativeSign = LineToFix
  10.     End If
  11. End Function
  12.  
Aug 16 '12 #10
Killer42
8,435 Expert 8TB
I'd just like to mention here that Instr() may be the function you were looking for. It searches a string for another string and tells you where (or whether) it occurs.
Aug 22 '12 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: chuck amadi | last post by:
By the way list is there a better way than using the readlines() to > > >parse the mail data into a file , because Im using > > >email.message_from_file it returns > > >all the data i.e reads one...
5
by: Andrew Slentz | last post by:
I have a format file which is working but not correctly. It is, for some reason, dropping the first line of the input .csv file. The problem is something with the second coulumn of data having...
1
by: Query Builder | last post by:
I am new to BCP. Can anyone help me understand this? I tried searching the BOL but it doesnt show much help on syntex. Lets say I have a simple table and want to out put the records into a file....
3
by: Paul Watson | last post by:
It is clear that just using 'print' with variable names is relatively uncontrollable. However, I thought that using a format string would reign the problem in and give the desired output. Must...
2
by: Paolo Pignatelli | last post by:
I am trying to get an output/file like this (below) in an XML file (MyXmlFile.xml) (which I will use for a slide show) -- <gallery timer="3" order="sequential" fadetime="2" looping="yes"...
0
by: neon123 | last post by:
i am using a sql loader to load data into oracle 8. i am using vbscript to run the sql loader. i need to pass username and password entered through vbscript ,,into the visual basic application . ...
2
by: tudyfruity18 | last post by:
I have to write a program that will reformat the data files given to me and create a new data file for each city. The desired output would be the cities name followed by the year( fixed four digits),...
1
by: Chris Ashley | last post by:
I have a stream of bytes (making up a large file) coming from somewhere, and need to send it to the user. I can't send it to Response.OutputStream because this is read only, and storing the entire...
5
Soniad
by: Soniad | last post by:
Hello, I want to include asp file within vbscript, this file name i am taking in variable . and when i use this variable in the include tag outside delimiters(<%%>), it does not work, <%Dim...
0
by: zizi2 | last post by:
Hi, how do I output multiple excel files from one source using vbscript? Regards, Noluthando
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.