Trimming text?

  • Thread starter Thread starter branigan
  • Start date Start date
B

branigan

I have been trying to come up with a way to report on our brightstor
backups. what I need is a report that will tell me the tape that was
used last night, without all of the other fluff. I parse the log file
and get a dump of everything that occurred on a certain date. However,
what I need is to be able to scan that parse/dump for the tape name. The
output follows:

P:\>findstr /i /c:"Serial #" c:\tools\02m1117.dat
11/17/04 12:01:33 3983 Use media 11/15/04 10:17 AM, serial #
BD8893L1, ID D6DF, sequence #1
11/17/04 12:11:39 3983.32 Backup Session 32 on Media 11/15/04 10:17
AM Serial # BD8893L1
11/17/04 17:34:10 4012 Use media 11/17/04 5:33 PM, serial #
BD8923L1, ID D833, sequence #1
11/17/04 17:45:54 4012.1 Backup Session 1 on Media 11/17/04 5:33PM
Serial # BD8923L1
11/17/04 23:15:31 4012.1 Format BD8592L1 as 11/17/04 5:33 PM (serial
# BD8573L1).
11/17/04 23:42:33 4012.2 Backup Session 2 on Media 11/17/04 5:33 PM
Serial # BD8573L1
11/17/04 23:54:16 4012.3 Backup Session 3 on Media 11/17/04 5:33 PM
Serial # BD8573L1
11/17/04 23:54:31 4012.4 Backup Session 4 on Media 11/17/04 5:33 PM
Serial # BD8573L1

The findstr is pretty consistant with what it provides. I would like to
get only the date i.e. 11/17/04, the time 23:xx and the serial number.
I want the report to look as follows:

11/17/04 17:34:10 BD8923L1
11/17/04 23:42:33 BD8573L1


the diffucult part for me is just getting to the slimmed down output.
 
branigan said:
I have been trying to come up with a way to report on our brightstor
backups. what I need is a report that will tell me the tape that was
used last night, without all of the other fluff. I parse the log file
and get a dump of everything that occurred on a certain date. However,
what I need is to be able to scan that parse/dump for the tape name. The
output follows:

P:\>findstr /i /c:"Serial #" c:\tools\02m1117.dat

Try this batch, it splits date, time, remaining part into %%A %%B %%C.
%%C is copied to sn and then trimmed by deleting up to "Serial # " and
cutting to 8 places.

@echo off&setlocal EnableDelayedExpansion
for /F "tokens=1-2*" %%A in (
'findstr /i /c:"Serial #" c:\tools\02m1117.dat'
) do set "SN=%%C"&set "SN=!SN:*Serial # =!"&echo %%A %%B !SN:~0,8!


BTW To keep us helping an acknowledgement or feedback would be nice.

HTH
 
My confusion with for comes after the do set ->"sn... Could you explain that
portion? Your script works great...
 
My confusion with for comes after the do set ->"sn... Could you explain that
portion? Your script works great...

Matthias Tacke said:
Try this batch, it splits date, time, remaining part into %%A %%B %%C.
%%C is copied to sn and then trimmed by deleting up to "Serial # " and
cutting to 8 places.

@echo off&setlocal EnableDelayedExpansion
for /F "tokens=1-2*" %%A in (
'findstr /i /c:"Serial #" c:\tools\02m1117.dat'
) do set "SN=%%C"&set "SN=!SN:*Serial # =!"&echo %%A %%B !SN:~0,8!


BTW To keep us helping an acknowledgement or feedback would be nice.

HTH

"SN=%%C"&set "SN=!SN:*Serial # =!"&echo %%A %%B !SN:~0,8!

Set a variable named SN to the 3rd token (after the 2nd blank).
Replace the string *Searial# in SN, using DelayedExpansion, with a nul.
Display the first and second tokens followed by the the first 8 positions of
the SN variable (using delayed expansion).


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
My confusion with for comes after the do set ->"sn... Could you explain that
portion? Your script works great...

Hi branigan.

Instead of enclosing several commands with parenthes you can line them
up with "&". This is equivalent to the above:

@echo off&setlocal EnableDelayedExpansion
for /F "tokens=1-2*" %%A in (
'findstr /i /c:"Serial #" c:\tools\02m1117.dat') do (
set "SN=%%C"
set "SN=!SN:*Serial # =!"
echo %%A %%B !SN:~0,8!
)

As already mentioned the %%C is copied to the var SN.
See set /? for help on exchanging parts of a var.
Here !SN:*Serial # =!" means all chars up to the space in front of the
serial number are replaced with nothing.
In the echo command !SN:~0,8! returns 8 chars from offset zero.

HTH
 
Jerold said:
"SN=%%C"&set "SN=!SN:*Serial # =!"&echo %%A %%B !SN:~0,8!

Set a variable named SN to the 3rd token (after the 2nd blank).
Replace the string *Searial# in SN, using DelayedExpansion, with a nul.
Display the first and second tokens followed by the the first 8 positions of
the SN variable (using delayed expansion).
Thanks for the reply Jerold,

I was interrupted while writing my own. There is to mention the
asterisk in the replacing set command stands for any preceeding chars.

@branigan
You have to pay attention that this command is case insensitive and
it uses the *first* occurence of a search string - i.e. it is *not*
greedy like regex's. See this example:

@echo off&setlocal
set "var=dummy dummy This is a demo of this command"
echo var=%var%
set var=%var:*this=that%
echo var=%var%

==screen=copy===================================================
var=dummy dummy This is a demo of this command
var=that is a demo of this command
==screen=copy===================================================

HTH
 
Back
Top