Check file size

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
RMSoares
Posts: 32
Joined: 06 Aug 2012 12:01

Check file size

#1 Post by RMSoares » 18 Mar 2013 10:33

Good afternoon,
I'm getting a set of files from ftp, with fixed size of 135 characters, from a mainframe, we have detected a number of errors in processing these files because same records appear to have different size than expected.

I would like to have a batch that validate the file size and contains special characters (NULLS, low values, /n, ...). Some of the gurus can provide me a batch that do this processing?


My input file will have (first and last record are correct, other have a wrong size):
    10001821700034095 2ALBANQUE, 435 3-2 4B 7860-160021000001*
    10131844006083203 2ATRANSFUE, 3434 2 JJ 7860-160021000001*
    10001821700034095 2FALTER, wefe 43 4-89 4A 2685160056700001*
    10503895023883403 2LUXER ATREWS, 999 3 1134-154241000054*

It is intended to identify the line 2,3 and 4 have a lower size than expected (135 characters), and get an output with the following information
    #Line 2 - 118 characters
    10131844006083203 2ATRANSFUE, 3434 2 JJ
    #Line 3 - 18 characters
    7860-160021000001*
    #Line 4 - 134 characters
    10001821700034095 2FALTER, wefe 43 4-89 4A 2685160056700001*

Can I get same help ?
thanks in advance

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Check file size

#2 Post by Squashman » 18 Mar 2013 12:39

I was thinking we could do this with some code that Dave gave me but it does a binary compare with FC so we could in theory tell you which lines are not 135 bytes but wouldn't be able to output what is in those lines because it is doing a binary compare to get the line length. Antonio also posted some code in that thread. I can't recall if he used different code to get the line length or not. Gotta go find that thread.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Check file size

#3 Post by Squashman » 18 Mar 2013 12:45

This was my original thread. It uses some code to get the length of the first line and then exits. This could be used to get the length of every line with some modifications.
viewtopic.php?f=3&t=2727&start=30

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Check file size

#4 Post by foxidrive » 18 Mar 2013 16:36

You have to use code tags to show the lines.

I can't see how the log you want correlates to the example you provided, but VBS is the way to go with this task.

RMSoares wrote:My input file will have (first and last record are correct, other have a wrong size):

Code: Select all

10001821700034095 2ALBANQUE, 435 3-2 4B                                                                              7860-160021000001*
10131844006083203 2ATRANSFUE,  3434 2 JJ                                                                              7860-160021000001*
10001821700034095 2FALTER, wefe 43 4-89 4A                                                                           2685160056700001*
10503895023883403 2LUXER ATREWS, 999 3                                                                               1134-154241000054*


It is intended to identify the line 2,3 and 4 have a lower size than expected (135 characters), and get an output with the following information

Code: Select all

#Line 2 -  118 characters
10131844006083203 2ATRANSFUE,  3434 2 JJ                                                                             
#Line 3 -  18 characters
7860-160021000001*
#Line 4 -  134 characters
10001821700034095 2FALTER, wefe 43 4-89 4A                                                                           2685160056700001*


Aacini
Expert
Posts: 1913
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Check file size

#5 Post by Aacini » 18 Mar 2013 18:37

You may use findstr's /O option to achieve this test, but you must be aware that this option report the byte position of the start of each line, so the bytes of the EndOfLine marker must be accounted. The Batch file below assume that the EndOfLine marker is CR+LF (two bytes):

Code: Select all

@echo off
setlocal EnableDelayedExpansion
set rightSize=135
set line=0
set lastOffset=
for /F "tokens=1* delims=:" %%a in ('findstr /O "^" %1') do (
   if defined lastOffset (
      set /A line+=1, lastSize=%%a-lastOffset-2
      if !lastSize! neq %rightSize% (
         echo #Line !line! - !lastSize! characters
         echo !lastLine!
      )
   )
   set lastOffset=%%a
   set lastLine=%%b
)
rem Check for the last line
set /A line+=1, lastSize=%~Z1-lastOffset-2
if !lastSize! neq %rightSize% (
   echo #Line !line! - !lastSize! characters
   echo !lastLine!
)

Output:

#Line 2 - 136 characters
10131844006083203 2ATRANSFUE, 3434 2 JJ
7860-160021000001*
#Line 3 - 134 characters
10001821700034095 2FALTER, wefe 43 4-89 4A
2685160056700001*

Antonio

Post Reply