Solved

Truncate a String batch file

Posted on 2006-07-04
5
1,207 Views
Last Modified: 2011-10-03
How can I truncate a string in batch programming.

http://www.experts-exchange.com/Programming/Q_21906374.html
0
Comment
Question by:life_j
5 Comments
 
LVL 15

Expert Comment

by:deepaknet
Comment Utility
A search got the following shareware utility http://www.novell.com/coolsolutions/tools/13549.html

0
 
LVL 11

Expert Comment

by:cup
Comment Utility
Rewrite it in Javascript or Vbscript and use cscript/wscript to run it.  You have the full programming capabilities plus access to OS stuff with WMI and access to command line stuff from the WSH interface.  It is far easier than struggling with the batch language.  Alternatively try putting your parameters in quotes

if "%%2"== "HO" echo ...
0
 
LVL 7

Author Comment

by:life_j
Comment Utility
Cup

can you tell how to do it a vbscript,

Thanks In advance
0
 
LVL 15

Accepted Solution

by:
bpmurray earned 400 total points
Comment Utility
You could try something like this:
Option Explicit

Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1
Const ForWriting = 2

Dim FSO, inName, inFile, txtLine, outName, outFile
Dim systemDate, objWSH, re1, re2, objNet
Dim codeLine, today, testTxt

Set re1 = new RegExp
re1.Pattern = "^.*\) \(Job: """
re1.Global = True
re1.IgnoreCase = False

Set re2 = new regexp
re2.Pattern = "\. .*$"
re2.Global = True
re2.IgnoreCase = False

Set objNet = WScript.CreateObject("WScript.Network")

inName="backupexec.log"
today = Date()
outName = Replace(Cstr(Today), "/", "") + ".txt"

Set objWSH = WScript.CreateObject("Wscript.Shell")
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
Set inFile = FSO.OpenTextFile(inName, ForReading, FailIfNotExist, OpenAsASCII)
Set outFile = FSO.OpenTextFile(outName, ForWriting, True)


Do Until inFile.AtEndOfStream
   txtLine = inFile.ReadLine
   codeLine = re1.Replace(txtLine, "")
   testTxt = Left(codeLine, 2)
   If  testTxt = "BR" Then
      txtLine = re2.Replace(codeLine, "")
      outFile.Write objNet.ComputerName & " " & today & " " & txtLine
   End If
Loop

inFile.Close
outFile.Close

objWSH.Popup "All Done!", 5, "", vbOKonly

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
maxMirror challenge 10 88
count7 challenge 12 67
noX challenge 17 76
wordappend challenge 8 84
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now