• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1229
  • Last Modified:

Truncate a String batch file

How can I truncate a string in batch programming.

http://www.experts-exchange.com/Programming/Q_21906374.html
0
life_j
Asked:
life_j
1 Solution
 
deepaknetCommented:
A search got the following shareware utility http://www.novell.com/coolsolutions/tools/13549.html

0
 
cupCommented:
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
 
life_jAuthor Commented:
Cup

can you tell how to do it a vbscript,

Thanks In advance
0
 
bpmurrayCommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now