Solved

Truncate a String batch file

Posted on 2006-07-04
5
1,221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 15

Expert Comment

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

0
 
LVL 11

Expert Comment

by:cup
ID: 17048503
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
ID: 17048692
Cup

can you tell how to do it a vbscript,

Thanks In advance
0
 
LVL 15

Accepted Solution

by:
bpmurray earned 400 total points
ID: 17049509
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to implement Singleton Design Pattern in Java.
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…

688 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