Solved

Truncate a String batch file

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adobe Customization Wizard XI issues 26 278
mirrorEnds challenge 6 151
MaxSpan challenge 9 138
Reccomended programming language for client-server applications 12 195
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This video teaches viewers about errors in exception handling.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

737 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