Solved

Truncate a String batch file

Posted on 2006-07-04
5
1,214 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
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
equalIsNot  challenge 43 172
zeroFront challenge 7 114
sumHeights  challenge 17 75
WPF issue with Trigger 2 115
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 will show, step by step, how to integrate R code into a R Sweave document
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

829 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